ARM: Samsung Exynos4210-based boards support.
Subsystems (2)
v3 cover ARM: Samsung Exynos4210-based boards support.
This set of patches adds support for Samsung S5PC210-based boards NURI and SMDKC210. Tested on Linux kernel v3.x series. Usage of "-smp 2" option is reuired for now.
Third version: Reverted hw/arm_gic.c modification. Added IRQ Gate to Exynos4210 board.
Evgeny Voevodin (8):
hw/sysbus.h: Increase maximum number of device IRQs.
ARM: exynos4210: IRQ subsystem support.
ARM: exynos4210: PWM support. hw/arm_boot.c: Add new secondary CPU bootloader.
ARM: exynos4210: MCT support. hw/exynos4210.c: Boot secondary CPU. hw/lan9118: Add basic 16-bit mode support. hw/exynos4210.c: Add LAN support for SMDKC210.
Maksim Kozlov (3):
ARM: Samsung exynos4210-based boards emulation
ARM: exynos4210: CMU support
ARM: exynos4210: UART support
Mitsyanko Igor (3):
hw/sd.c, hw/sd.h: add receive ready query routine to SD/MMC API
ARM: exynos4210: added SD/MMC host controller
ARM: exynos4210: added display controller implementation
Makefile.target | 3 + hw/arm-misc.h | 1 + hw/arm_boot.c | 22 +- hw/devices.h | 2 +- hw/exynos4210.c | 561 +++++++++++++++ hw/exynos4210.h | 107 +++ hw/exynos4210_cmu.c | 1146 ++++++++++++++++++++++++++++++ hw/exynos4210_combiner.c | 385 ++++++++++ hw/exynos4210_fimd.c | 1737 ++++++++++++++++++++++++++++++++++++++++++++++ hw/exynos4210_gic.c | 510 ++++++++++++++ hw/exynos4210_mct.c | 1486 +++++++++++++++++++++++++++++++++++++++ hw/exynos4210_pwm.c | 433 ++++++++++++ hw/exynos4210_sdhc.c | 1666 ++++++++++++++++++++++++++++++++++++++++++++ hw/exynos4210_uart.c | 674 ++++++++++++++++++ hw/lan9118.c | 115 +++- hw/sd.c | 5 + hw/sd.h | 1 + hw/sysbus.h | 2 +- 18 files changed, 8840 insertions(+), 16 deletions(-) create mode 100644 hw/exynos4210.c create mode 100644 hw/exynos4210.h create mode 100644 hw/exynos4210_cmu.c create mode 100644 hw/exynos4210_combiner.c create mode 100644 hw/exynos4210_fimd.c create mode 100644 hw/exynos4210_gic.c create mode 100644 hw/exynos4210_mct.c create mode 100644 hw/exynos4210_pwm.c create mode 100644 hw/exynos4210_sdhc.c create mode 100644 hw/exynos4210_uart.c
Signature · 1 line
1.7.4.1
PATCH v3 1/14 ARM: Samsung exynos4210-based boards emulation
From: Maksim Kozlov <[email protected]>
Add initial code for support of NURI and SMDKC210 boards
--- Makefile.target | 1 + hw/exynos4210.c | 224 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/exynos4210.h | 34 ++++++++ 3 files changed, 259 insertions(+), 0 deletions(-) create mode 100644 hw/exynos4210.c create mode 100644 hw/exynos4210.h
Makefile.target +1 -0
@@ -344,6 +344,7 @@ obj-arm-y = integratorcp.o versatilepb.o arm_pic.o arm_timer.o obj-arm-y += arm_boot.o pl011.o pl031.o pl050.o pl080.o pl110.o pl181.o pl190.o obj-arm-y += versatile_pci.o obj-arm-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.o +obj-arm-y += exynos4210.o obj-arm-y += armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o obj-arm-y += pl061.o obj-arm-y += arm-semi.o
hw/exynos4210.c new file +224 -0
224 lines not on this page · raw message
hw/exynos4210.h new file +34 -0
@@ -0,0 +1,34 @@ +/* +* Samsung exynos4210-based boards emulation +* +* Copyright (c) 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Maksim Kozlov <[email protected]> +* Evgeny Voevodin <[email protected]> +* Igor Mitsyanko <[email protected]> +* +* +* 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, write to the Free Software Foundation, Inc., 51 +* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* +*/ + + +#ifndef EXYNOS4210_H_ +#define EXYNOS4210_H_ + +#include "qemu-common.h" + +#define EXYNOS4210_MAX_CPUS 2 + +#endif /* EXYNOS4210_H_ */
Signature · 1 line
1.7.4.1
Re: [Qemu-devel] [PATCH v3 01/14] ARM: Samsung exynos4210-based boards emulation
Quoted 3 lines · Evgeny Voevodin
From: Maksim Kozlov <[email protected]>
Add initial code for support of NURI and SMDKC210 boards
This patch doesn't compile:
/home/pm215/src/qemu/qemu/hw/exynos4210.c: In function ‘exynos4210_init’:/home/pm215/src/qemu/qemu/hw/exynos4210.c:98:14: error: variable ‘cpu_irq’ set but not used [-Werror=unused-but-set-variable]
cc1: all warnings being treated as errors
Quoted 240 lines
---
Makefile.target | 1 + hw/exynos4210.c | 224 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/exynos4210.h | 34 ++++++++ 3 files changed, 259 insertions(+), 0 deletions(-)create mode 100644
hw/exynos4210.c
create mode 100644hw/exynos4210.hMakefile.target +0
-0@@ -344,6 +344,7 @@ obj-arm-y = integratorcp.o versatilepb.o arm_pic.o arm_timer.oobj-arm-y += arm_boot.o pl011.o pl031.o pl050.o pl080.o pl110.o pl181.o pl190.o obj-arm-y += versatile_pci.o
obj-arm-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.o +obj-arm-y += exynos4210.o
obj-arm-y += armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o obj-arm-y += pl061.o
obj-arm-y += arm-semi.ohw/exynos4210.c new file +214
-0@@ -0,0 +1,224 @@ +/* +* Samsung exynos4210-based boards emulation +* +* Copyright (c) 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Maksim Kozlov <[email protected]> +* Evgeny Voevodin <[email protected]> +* Igor Mitsyanko <[email protected]> +* +* 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, write to the Free Software Foundation, Inc., 51 +* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* +*/ + +#include "boards.h" +#include "sysemu.h" +#include "sysbus.h" +#include "arm-misc.h" +#include "exec-memory.h" +#include "exynos4210.h" + +#undef DEBUG + +//#define DEBUG + +#ifdef DEBUG + #undef PRINT_DEBUG + #define PRINT_DEBUG(fmt, args...) \ + do { \ + fprintf(stderr, " [%s:%d] "fmt, __func__, __LINE__, ##args); \ + } while (0) +#else + #define PRINT_DEBUG(fmt, args...) \ + do {} while (0) +#endif + +#define EXYNOS4210_DRAM0_BASE_ADDR 0x40000000 +#define EXYNOS4210_DRAM1_BASE_ADDR 0xa0000000 +#define EXYNOS4210_DRAM_MAX_SIZE 0x60000000/* 1.5 GB */ + +#define EXYNOS4210_IROM_BASE_ADDR 0x00000000 +#define EXYNOS4210_IROM_SIZE 0x00010000/* 64 KB */ +#define EXYNOS4210_IROM_MIRROR_BASE_ADDR 0x02000000 +#define EXYNOS4210_IROM_MIRROR_SIZE 0x00010000/* 64 KB */ + +#define EXYNOS4210_IRAM_BASE_ADDR 0x02020000 +#define EXYNOS4210_IRAM_SIZE 0x00020000/* 128 KB */ + +#define EXYNOS4210_SFR_BASE_ADDR 0x10000000 + +#define EXYNOS4210_BASE_BOOT_ADDR EXYNOS4210_DRAM0_BASE_ADDR + +static struct arm_boot_info exynos4210_binfo = { + .loader_start = EXYNOS4210_BASE_BOOT_ADDR, +}; + +static uint8_t chipid_and_omr[] = {0x11 ,0x02 ,0x21 ,0x43 , + 0x09, 0x00, 0x00, 0x00 }; + +enum exynos4210_board_type { + BOARD_EXYNOS4210_NURI, + BOARD_EXYNOS4210_SMDKC210, +}; + +enum exynos4210_mach_id { + MACH_NURI_ID = 0xD33, + MACH_SMDKC210_ID = 0xB16, +}; + + +static void exynos4210_init (ram_addr_t ram_size, + const char *boot_device, + const char *kernel_filename, + const char *kernel_cmdline, + const char *initrd_filename, + const char *cpu_model, + enum exynos4210_board_type board_type) +{ + CPUState *env; + MemoryRegion *system_mem = get_system_memory(); + MemoryRegion *chipid_mem = g_new(MemoryRegion, 1); + MemoryRegion *iram_mem = g_new(MemoryRegion, 1); + MemoryRegion *irom_mem = g_new(MemoryRegion, 1); + MemoryRegion *irom_alias_mem = g_new(MemoryRegion, 1); + MemoryRegion *dram0_mem = g_new(MemoryRegion, 1); + MemoryRegion *dram1_mem = NULL; + qemu_irq *irqp; + qemu_irq cpu_irq[4]; + ram_addr_t mem_size; + int n; + + switch (board_type) { + case BOARD_EXYNOS4210_NURI: + exynos4210_binfo.board_id = MACH_NURI_ID; + break; + case BOARD_EXYNOS4210_SMDKC210: + exynos4210_binfo.board_id = MACH_SMDKC210_ID; + break; + default: + break; + } + if (!cpu_model) { + cpu_model = "cortex-a9"; + } + + for (n = 0; n < smp_cpus; n++) { + env = cpu_init(cpu_model); + if (!env) { + fprintf(stderr, "Unable to find CPU %d definition\n", n); + exit(1); + } + /* Create PIC controller for each processor instance */ + irqp = arm_pic_init_cpu(env); + + /* + * Get GICs gpio_in cpu_irq to connect a combiner to them later. + * Use only IRQ for a while. + */ + cpu_irq[n] = irqp[ARM_PIC_CPU_IRQ]; + } + + /*** Memory ***/ + + /* Chip-ID and OMR */ + memory_region_init_ram_ptr(chipid_mem, NULL, "exynos4210.chipid", + sizeof(chipid_and_omr), chipid_and_omr); + memory_region_set_readonly(chipid_mem, true); + memory_region_add_subregion(system_mem, EXYNOS4210_SFR_BASE_ADDR, + chipid_mem); + + /* Internal ROM */ + memory_region_init_ram(irom_mem, NULL, "exynos4210.irom", + EXYNOS4210_IROM_SIZE); + memory_region_set_readonly(irom_mem, true); + memory_region_add_subregion(system_mem, EXYNOS4210_IROM_BASE_ADDR, + irom_mem); + /* mirror of 0x0 – 0x10000 */ + memory_region_init_alias(irom_alias_mem, "exynos4210.irom_alias", + irom_mem, 0, EXYNOS4210_IROM_SIZE); + memory_region_set_readonly(irom_alias_mem, true); + memory_region_add_subregion(system_mem, EXYNOS4210_IROM_MIRROR_BASE_ADDR, + irom_alias_mem); + + /* Internal RAM */ + memory_region_init_ram(iram_mem, NULL, "exynos4210.iram", + EXYNOS4210_IRAM_SIZE); + memory_region_set_readonly(iram_mem, false); + memory_region_add_subregion(system_mem, EXYNOS4210_IRAM_BASE_ADDR, + iram_mem); + + /* DRAM */ + mem_size = ram_size; + if (mem_size > EXYNOS4210_DRAM_MAX_SIZE) { + dram1_mem = g_new(MemoryRegion, 1); + memory_region_init_ram(dram1_mem, NULL, "exynos4210.dram1", + mem_size - EXYNOS4210_DRAM_MAX_SIZE); + memory_region_add_subregion(system_mem, EXYNOS4210_DRAM1_BASE_ADDR, + dram1_mem); + mem_size = EXYNOS4210_DRAM_MAX_SIZE; + } + memory_region_init_ram(dram0_mem, NULL, "exynos4210.dram0", mem_size); + memory_region_add_subregion(system_mem, EXYNOS4210_DRAM0_BASE_ADDR, + dram0_mem); + + /*** Load kernel ***/ + + exynos4210_binfo.ram_size = ram_size; + exynos4210_binfo.nb_cpus = smp_cpus; + exynos4210_binfo.kernel_filename = kernel_filename; + exynos4210_binfo.initrd_filename = initrd_filename; + exynos4210_binfo.kernel_cmdline = kernel_cmdline; + + arm_load_kernel(first_cpu, &exynos4210_binfo); +} + +static void exynos4210_nuri_init (ram_addr_t ram_size, + const char *boot_device, + const char *kernel_filename, const char *kernel_cmdline, + const char *initrd_filename, const char *cpu_model) +{ + exynos4210_init(ram_size, boot_device, kernel_filename, kernel_cmdline, + initrd_filename, cpu_model, BOARD_EXYNOS4210_NURI); +} + +static void exynos4210_smdkc210_init (ram_addr_t ram_size, + const char *boot_device, + const char *kernel_filename, const char *kernel_cmdline, + const char *initrd_filename, const char *cpu_model) +{ + exynos4210_init(ram_size, boot_device, kernel_filename, kernel_cmdline, + initrd_filename, cpu_model, BOARD_EXYNOS4210_SMDKC210); +} + +static QEMUMachine exynos4210_nuri_machine = { + .name = "exynos4210-nuri", + .desc = "Samsung Exynos4210 NURI board", + .init = exynos4210_nuri_init, + .max_cpus = EXYNOS4210_MAX_CPUS, +}; + +static QEMUMachine exynos4210_smdkc210_machine = { + .name = "exynos4210-smdkc210", + .desc = "Samsung Exynos4210 SMDKC210 board", + .init = exynos4210_smdkc210_init,
hw/exynos4210.c line 224
Quoted 10 lines
hw/exynos4210.c new file +10
-0+ .max_cpus = EXYNOS4210_MAX_CPUS, +}; + +static void exynos4210_machine_init (void ) +{ + qemu_register_machine(&exynos4210_nuri_machine); + qemu_register_machine(&exynos4210_smdkc210_machine); +} + +machine_init (exynos4210_machine_init);
This file is mixing up code for the SoC with code for individual boards. The SoC specific code should be in its own file, and then the board initialisation file should say "init the SoC, now add the things which are external to the SoC and specific to this board". (This is how the omap code is structured, for instance.)
Quoted 41 lines
hw/exynos4210.h new file +34
-1@@ -0,0 +1,34 @@ +/* +* Samsung exynos4210-based boards emulation +* +* Copyright (c) 2011 Samsung Electronics Co., Ltd. All rights reserved. +* Maksim Kozlov <[email protected]> +* Evgeny Voevodin <[email protected]> +* Igor Mitsyanko <[email protected]> +* +* +* 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, write to the Free Software Foundation, Inc., 51 +* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* +*/ + + +#ifndef EXYNOS4210_H_ +#define EXYNOS4210_H_ + +#include "qemu-common.h" + +#define EXYNOS4210_MAX_CPUS 2 + +#endif /* EXYNOS4210_H_ */ --
Quoted 1 line
1.7.4.1
-- PMM
PATCH v3 2/14 ARM: exynos4210: CMU support
In reply to Evgeny VoevodinFrom: Maksim Kozlov <[email protected]>
Add exynos4210 Clock Management Units emulation
--- Makefile.target | 2 +- hw/exynos4210.c | 7 + hw/exynos4210.h | 22 + hw/exynos4210_cmu.c | 1146 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 1176 insertions(+), 1 deletions(-) create mode 100644 hw/exynos4210_cmu.c
Makefile.target +1 -1
@@ -344,7 +344,7 @@ obj-arm-y = integratorcp.o versatilepb.o arm_pic.o arm_timer.o obj-arm-y += arm_boot.o pl011.o pl031.o pl050.o pl080.o pl110.o pl181.o pl190.o obj-arm-y += versatile_pci.o obj-arm-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.o -obj-arm-y += exynos4210.o +obj-arm-y += exynos4210.o exynos4210_cmu.o obj-arm-y += armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o obj-arm-y += pl061.o obj-arm-y += arm-semi.o
hw/exynos4210.c +7 -0
@@ -60,6 +60,10 @@#define EXYNOS4210_BASE_BOOT_ADDR EXYNOS4210_DRAM0_BASE_ADDR +/* SFR Base Address for CMUs */ +#define EXYNOS4210_CMU_BASE_ADDR 0x10030000 + +static struct arm_boot_info exynos4210_binfo = { .loader_start =EXYNOS4210_BASE_BOOT_ADDR , };
@@ -172,6 +176,9 @@ static void exynos4210_init(ram_addr_t ram_size,memory_region_add_subregion (system_mem,EXYNOS4210_DRAM0_BASE_ADDR , dram0_mem); +/* CMU */ +sysbus_create_simple ("exynos4210.cmu" ,EXYNOS4210_CMU_BASE_ADDR ,NULL ); +/*** Load kernel ***/ exynos4210_binfo.ram_size = ram_size;
hw/exynos4210.h +22 -0
@@ -31,4 +31,26 @@#define EXYNOS4210_MAX_CPUS 2 +/* +* Interface for exynos4210 Clock Management Units (CMUs) +*/ + +typedef enum { +XXTI , +XUSBXTI , +APLL , +MPLL , +SCLK_APLL , +SCLK_MPLL , +ACLK_100 , +SCLK_UART0 , +SCLK_UART1 , +SCLK_UART2 , +SCLK_UART3 , +SCLK_UART4 , +CLOCKS_NUMBER +}Exynos4210CmuClock ; + +uint64_t exynos4210_cmu_get_rate (Exynos4210CmuClock clock); +#endif /* EXYNOS4210_H_ */
hw/exynos4210_cmu.c new file +1146 -0
1,146 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Re: [Qemu-devel] [PATCH v3 02/14] ARM: exynos4210: CMU support
Quoted 530 lines · Evgeny Voevodin
From: Maksim Kozlov <[email protected]>
Add exynos4210 Clock Management Units emulation
Signed-off-by Evgeny Voevodin <[email protected]>---
Makefile.target | 2 +- hw/exynos4210.c | 7 + hw/exynos4210.h | 22 + hw/exynos4210_cmu.c | 1146 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 1176 insertions(+), 1 deletions(-)create mode 100644
hw/exynos4210_cmu.cMakefile.target +0
-0@@ -344,7 +344,7 @@ obj-arm-y = integratorcp.o versatilepb.o arm_pic.o arm_timer.oobj-arm-y += arm_boot.o pl011.o pl031.o pl050.o pl080.o pl110.o pl181.o pl190.o obj-arm-y += versatile_pci.o
obj-arm-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.oMakefile.target +1
-1-obj-arm-y += exynos4210.o +obj-arm-y += exynos4210.o exynos4210_cmu.oobj-arm-y += armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o obj-arm-y += pl061.o
obj-arm-y += arm-semi.ohw/exynos4210.c +7
-0@@ -60,6 +60,10 @@ #define EXYNOS4210_BASE_BOOT_ADDR EXYNOS4210_DRAM0_BASE_ADDR +/* SFR Base Address for CMUs */ +#define EXYNOS4210_CMU_BASE_ADDR 0x10030000 + + static struct arm_boot_info exynos4210_binfo = { .loader_start = EXYNOS4210_BASE_BOOT_ADDR, };@@ -172,6 +176,9 @@ static void exynos4210_init(ram_addr_t ram_size, memory_region_add_subregion(system_mem, EXYNOS4210_DRAM0_BASE_ADDR, dram0_mem); + /* CMU */ + sysbus_create_simple("exynos4210.cmu", EXYNOS4210_CMU_BASE_ADDR, NULL); + /*** Load kernel ***/ exynos4210_binfo.ram_size = ram_size;hw/exynos4210.h +22
-0@@ -31,4 +31,26 @@ #define EXYNOS4210_MAX_CPUS 2 +/* +* Interface for exynos4210 Clock Management Units (CMUs) +*/ + +typedef enum { + XXTI, + XUSBXTI, + APLL, + MPLL, + SCLK_APLL, + SCLK_MPLL, + ACLK_100, + SCLK_UART0, + SCLK_UART1, + SCLK_UART2, + SCLK_UART3, + SCLK_UART4, + CLOCKS_NUMBER +}Exynos4210CmuClock ; + +uint64_t exynos4210_cmu_get_rate (Exynos4210CmuClock clock); + #endif /* EXYNOS4210_H_ */hw/exynos4210_cmu.c new file +442
-0@@ -0,0 +1,1146 @@ +/* +* exynos4210 Clock Management Units (CMUs) Emulation +* +* Copyright (C) 2011 Samsung Electronics Co Ltd. +* Maksim Kozlov, <[email protected]> +* +* Created on: 07.2011 +* +* +* 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, write to the Free Software Foundation, Inc., 51 +* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* +*/ + +#include "sysbus.h" + +#include "exynos4210.h" + + + +#undef DEBUG_CMU + +//#define DEBUG_CMU +//#define DEBUG_CMU_EXTEND + + +#define PRINT_DEBUG(fmt, args...) \ + do {} while (0) +#define PRINT_DEBUG_SIMPLE(fmt, args...) \ + do {} while (0) +#define PRINT_DEBUG_EXTEND(fmt, args...) \ + do {} while (0) +#define PRINT_ERROR(fmt, args...) \ + do { \ + fprintf(stderr, " [%s:%d] "fmt, __func__, __LINE__, ##args); \ + } while (0) + + +#ifdef DEBUG_CMU + + #undef PRINT_DEBUG + #define PRINT_DEBUG(fmt, args...) \ + do { \ + fprintf(stderr, " [%s:%d] "fmt, __func__, __LINE__, ##args); \ + } while (0) + + #undef PRINT_DEBUG_SIMPLE + #define PRINT_DEBUG_SIMPLE(fmt, args...) \ + do { \ + fprintf(stderr, fmt, ## args); \ + } while (0) + +#ifdef DEBUG_CMU_EXTEND + + #undef PRINT_DEBUG_EXTEND + #define PRINT_DEBUG_EXTEND(fmt, args...) \ + do { \ + fprintf(stderr, " [%s:%d] "fmt, __func__, __LINE__, ##args); \ + } while (0) + +#endif /* EXTEND */ +#endif + + +/* +* Offsets for CMUs registers +*/ + +/* CMU_LEFTBUS registers */ +#define CLK_SRC_LEFTBUS 0x04200 +#define CLK_MUX_STAT_LEFTBUS 0x04400 +#define CLK_DIV_LEFTBUS 0x04500 +#define CLK_DIV_STAT_LEFTBUS 0x04600 +#define CLK_GATE_IP_LEFTBUS 0x04800 +#define CLKOUT_CMU_LEFTBUS 0x04A00 +#define CLKOUT_CMU_LEFTBUS_DIV_STAT 0x04A04 +/* CMU_RIGHTBUS registers */ +#define CLK_SRC_RIGHTBUS 0x08200 +#define CLK_MUX_STAT_RIGHTBUS 0x08400 +#define CLK_DIV_RIGHTBUS 0x08500 +#define CLK_DIV_STAT_RIGHTBUS 0x08600 +#define CLK_GATE_IP_RIGHTBUS 0x08800 +#define CLKOUT_CMU_RIGHTBUS 0x08A00 +#define CLKOUT_CMU_RIGHTBUS_DIV_STAT 0x08A04 +/* CMU_TOP registers */ +#define EPLL_LOCK 0x0C010 +#define VPLL_LOCK 0x0C020 +#define EPLL_CON0 0x0C110 +#define EPLL_CON1 0x0C114 +#define VPLL_CON0 0x0C120 +#define VPLL_CON1 0x0C124 +#define CLK_SRC_TOP0 0x0C210 +#define CLK_SRC_TOP1 0x0C214 +#define CLK_SRC_CAM 0x0C220 +#define CLK_SRC_TV 0x0C224 +#define CLK_SRC_MFC 0x0C228 +#define CLK_SRC_G3D 0x0C22C +#define CLK_SRC_IMAGE 0x0C230 +#define CLK_SRC_LCD0 0x0C234 +#define CLK_SRC_LCD1 0x0C238 +#define CLK_SRC_MAUDIO 0x0C23C +#define CLK_SRC_FSYS 0x0C240 +#define CLK_SRC_PERIL0 0x0C250 +#define CLK_SRC_PERIL1 0x0C254 +#define CLK_SRC_MASK_TOP 0x0C310 +#define CLK_SRC_MASK_CAM 0x0C320 +#define CLK_SRC_MASK_TV 0x0C324 +#define CLK_SRC_MASK_LCD0 0x0C334 +#define CLK_SRC_MASK_LCD1 0x0C338 +#define CLK_SRC_MASK_MAUDIO 0x0C33C +#define CLK_SRC_MASK_FSYS 0x0C340 +#define CLK_SRC_MASK_PERIL0 0x0C350 +#define CLK_SRC_MASK_PERIL1 0x0C354 +#define CLK_MUX_STAT_TOP 0x0C410 +#define CLK_MUX_STAT_MFC 0x0C428 +#define CLK_MUX_STAT_G3D 0x0C42C +#define CLK_MUX_STAT_IMAGE 0x0C430 +#define CLK_DIV_TOP 0x0C510 +#define CLK_DIV_CAM 0x0C520 +#define CLK_DIV_TV 0x0C524 +#define CLK_DIV_MFC 0x0C528 +#define CLK_DIV_G3D 0x0C52C +#define CLK_DIV_IMAGE 0x0C530 +#define CLK_DIV_LCD0 0x0C534 +#define CLK_DIV_LCD1 0x0C538 +#define CLK_DIV_MAUDIO 0x0C53C +#define CLK_DIV_FSYS0 0x0C540 +#define CLK_DIV_FSYS1 0x0C544 +#define CLK_DIV_FSYS2 0x0C548 +#define CLK_DIV_FSYS3 0x0C54C +#define CLK_DIV_PERIL0 0x0C550 +#define CLK_DIV_PERIL1 0x0C554 +#define CLK_DIV_PERIL2 0x0C558 +#define CLK_DIV_PERIL3 0x0C55C +#define CLK_DIV_PERIL4 0x0C560 +#define CLK_DIV_PERIL5 0x0C564 +#define CLKDIV2_RATIO 0x0C580 +#define CLK_DIV_STAT_TOP 0x0C610 +#define CLK_DIV_STAT_CAM 0x0C620 +#define CLK_DIV_STAT_TV 0x0C624 +#define CLK_DIV_STAT_MFC 0x0C628 +#define CLK_DIV_STAT_G3D 0x0C62C +#define CLK_DIV_STAT_IMAGE 0x0C630 +#define CLK_DIV_STAT_LCD0 0x0C634 +#define CLK_DIV_STAT_LCD1 0x0C638 +#define CLK_DIV_STAT_MAUDIO 0x0C63C +#define CLK_DIV_STAT_FSYS0 0x0C640 +#define CLK_DIV_STAT_FSYS1 0x0C644 +#define CLK_DIV_STAT_FSYS2 0x0C648 +#define CLK_DIV_STAT_FSYS3 0x0C64C +#define CLK_DIV_STAT_PERIL0 0x0C650 +#define CLK_DIV_STAT_PERIL1 0x0C654 +#define CLK_DIV_STAT_PERIL2 0x0C658 +#define CLK_DIV_STAT_PERIL3 0x0C65C +#define CLK_DIV_STAT_PERIL4 0x0C660 +#define CLK_DIV_STAT_PERIL5 0x0C664 +#define CLKDIV2_STAT 0x0C680 +#define CLK_GATE_SCLK_CAM 0x0C820 +#define CLK_GATE_IP_CAM 0x0C920 +#define CLK_GATE_IP_TV 0x0C924 +#define CLK_GATE_IP_MFC 0x0C928 +#define CLK_GATE_IP_G3D 0x0C92C +#define CLK_GATE_IP_IMAGE 0x0C930 +#define CLK_GATE_IP_LCD0 0x0C934 +#define CLK_GATE_IP_LCD1 0x0C938 +#define CLK_GATE_IP_FSYS 0x0C940 +#define CLK_GATE_IP_GPS 0x0C94C +#define CLK_GATE_IP_PERIL 0x0C950 +#define CLK_GATE_IP_PERIR 0x0C960 +#define CLK_GATE_BLOCK 0x0C970 +#define CLKOUT_CMU_TOP 0x0CA00 +#define CLKOUT_CMU_TOP_DIV_STAT 0x0CA04 +/* CMU_DMC registers */ +#define CLK_SRC_DMC 0x10200 +#define CLK_SRC_MASK_DMC 0x10300 +#define CLK_MUX_STAT_DMC 0x10400 +#define CLK_DIV_DMC0 0x10500 +#define CLK_DIV_DMC1 0x10504 +#define CLK_DIV_STAT_DMC0 0x10600 +#define CLK_DIV_STAT_DMC1 0x10604 +#define CLK_GATE_IP_DMC 0x10900 +#define CLKOUT_CMU_DMC 0x10A00 +#define CLKOUT_CMU_DMC_DIV_STAT 0x10A04 +#define DCGIDX_MAP0 0x11000 +#define DCGIDX_MAP1 0x11004 +#define DCGIDX_MAP2 0x11008 +#define DCGPERF_MAP0 0x11020 +#define DCGPERF_MAP1 0x11024 +#define DVCIDX_MAP 0x11040 +#define FREQ_CPU 0x11060 +#define FREQ_DPM 0x11064 +#define DVSEMCLK_EN 0x11080 +#define MAXPERF 0x11084 +#define APLL_LOCK 0x14000 +#define MPLL_LOCK 0x14008 +#define APLL_CON0 0x14100 +#define APLL_CON1 0x14104 +#define MPLL_CON0 0x14108 +#define MPLL_CON1 0x1410C +/* CMU_CPU registers */ +#define CLK_SRC_CPU 0x14200 +#define CLK_MUX_STAT_CPU 0x14400 +#define CLK_DIV_CPU0 0x14500 +#define CLK_DIV_CPU1 0x14504 +#define CLK_DIV_STAT_CPU0 0x14600 +#define CLK_DIV_STAT_CPU1 0x14604 +#define CLK_GATE_SCLK_CPU 0x14800 +#define CLK_GATE_IP_CPU 0x14900 +#define CLKOUT_CMU_CPU 0x14A00 +#define CLKOUT_CMU_CPU_DIV_STAT 0x14A04 +#define ARMCLK_STOPCTRL 0x15000 +#define ATCLK_STOPCTRL 0x15004 +#define PARITYFAIL_STATUS 0x15010 +#define PARITYFAIL_CLEAR 0x15014 +#define PWR_CTRL 0x15020 +#define APLL_CON0_L8 0x15100 +#define APLL_CON0_L7 0x15104 +#define APLL_CON0_L6 0x15108 +#define APLL_CON0_L5 0x1510C +#define APLL_CON0_L4 0x15110 +#define APLL_CON0_L3 0x15114 +#define APLL_CON0_L2 0x15118 +#define APLL_CON0_L1 0x1511C +#define IEM_CONTROL 0x15120 +#define APLL_CON1_L8 0x15200 +#define APLL_CON1_L7 0x15204 +#define APLL_CON1_L6 0x15208 +#define APLL_CON1_L5 0x1520C +#define APLL_CON1_L4 0x15210 +#define APLL_CON1_L3 0x15214 +#define APLL_CON1_L2 0x15218 +#define APLL_CON1_L1 0x1521C +#define CLKDIV_IEM_L8 0x15300 +#define CLKDIV_IEM_L7 0x15304 +#define CLKDIV_IEM_L6 0x15308 +#define CLKDIV_IEM_L5 0x1530C +#define CLKDIV_IEM_L4 0x15310 +#define CLKDIV_IEM_L3 0x15314 +#define CLKDIV_IEM_L2 0x15318 +#define CLKDIV_IEM_L1 0x1531C + + +typedef struct Exynos4210CmuReg { + const char *name; /* for debugging */ + uint32_t offset; + uint32_t reset_value; +}Exynos4210CmuReg ; + + +static Exynos4210CmuReg exynos4210_cmu_regs[] = { + /* CMU_LEFTBUS registers */ + {"CLK_SRC_LEFTBUS", CLK_SRC_LEFTBUS, 0x00000000}, + {"CLK_MUX_STAT_LEFTBUS", CLK_MUX_STAT_LEFTBUS, 0x00000001}, + {"CLK_DIV_LEFTBUS", CLK_DIV_LEFTBUS, 0x00000000}, + {"CLK_DIV_STAT_LEFTBUS", CLK_DIV_STAT_LEFTBUS, 0x00000000}, + {"CLK_GATE_IP_LEFTBUS", CLK_GATE_IP_LEFTBUS, 0xFFFFFFFF}, + {"CLKOUT_CMU_LEFTBUS", CLKOUT_CMU_LEFTBUS, 0x00010000}, + {"CLKOUT_CMU_LEFTBUS_DIV_STAT", CLKOUT_CMU_LEFTBUS_DIV_STAT, 0x00000000}, + /* CMU_RIGHTBUS registers */ + {"CLK_SRC_RIGHTBUS", CLK_SRC_RIGHTBUS, 0x00000000}, + {"CLK_MUX_STAT_RIGHTBUS", CLK_MUX_STAT_RIGHTBUS, 0x00000001}, + {"CLK_DIV_RIGHTBUS", CLK_DIV_RIGHTBUS, 0x00000000}, + {"CLK_DIV_STAT_RIGHTBUS", CLK_DIV_STAT_RIGHTBUS, 0x00000000}, + {"CLK_GATE_IP_RIGHTBUS", CLK_GATE_IP_RIGHTBUS, 0xFFFFFFFF}, + {"CLKOUT_CMU_RIGHTBUS", CLKOUT_CMU_RIGHTBUS, 0x00010000}, + {"CLKOUT_CMU_RIGHTBUS_DIV_STAT", CLKOUT_CMU_RIGHTBUS_DIV_STAT, 0x00000000}, + /* CMU_TOP registers */ + {"EPLL_LOCK", EPLL_LOCK, 0x00000FFF}, + {"VPLL_LOCK", VPLL_LOCK, 0x00000FFF}, + {"EPLL_CON0", EPLL_CON0, 0x00300301}, + {"EPLL_CON1", EPLL_CON1, 0x00000000}, + {"VPLL_CON0", VPLL_CON0, 0x00240201}, + {"VPLL_CON1", VPLL_CON1, 0x66010464}, + {"CLK_SRC_TOP0", CLK_SRC_TOP0, 0x00000000}, + {"CLK_SRC_TOP1", CLK_SRC_TOP1, 0x00000000}, + {"CLK_SRC_CAM", CLK_SRC_CAM, 0x11111111}, + {"CLK_SRC_TV", CLK_SRC_TV, 0x00000000}, + {"CLK_SRC_MFC", CLK_SRC_MFC, 0x00000000}, + {"CLK_SRC_G3D", CLK_SRC_G3D, 0x00000000}, + {"CLK_SRC_IMAGE", CLK_SRC_IMAGE, 0x00000000}, + {"CLK_SRC_LCD0", CLK_SRC_LCD0, 0x00001111}, + {"CLK_SRC_LCD1", CLK_SRC_LCD1, 0x00001111}, + {"CLK_SRC_MAUDIO", CLK_SRC_MAUDIO, 0x00000005}, + {"CLK_SRC_FSYS", CLK_SRC_FSYS, 0x00011111}, + {"CLK_SRC_PERIL0", CLK_SRC_PERIL0, 0x00011111}, + {"CLK_SRC_PERIL1", CLK_SRC_PERIL1, 0x01110055}, + {"CLK_SRC_MASK_TOP", CLK_SRC_MASK_TOP, 0x00000001}, + {"CLK_SRC_MASK_CAM", CLK_SRC_MASK_CAM, 0x11111111}, + {"CLK_SRC_MASK_TV", CLK_SRC_MASK_TV, 0x00000111}, + {"CLK_SRC_MASK_LCD0", CLK_SRC_MASK_LCD0, 0x00001111}, + {"CLK_SRC_MASK_LCD1", CLK_SRC_MASK_LCD1, 0x00001111}, + {"CLK_SRC_MASK_MAUDIO", CLK_SRC_MASK_MAUDIO, 0x00000001}, + {"CLK_SRC_MASK_FSYS", CLK_SRC_MASK_FSYS, 0x01011111}, + {"CLK_SRC_MASK_PERIL0", CLK_SRC_MASK_PERIL0, 0x00011111}, + {"CLK_SRC_MASK_PERIL1", CLK_SRC_MASK_PERIL1, 0x01110111}, + {"CLK_MUX_STAT_TOP", CLK_MUX_STAT_TOP, 0x11111111}, + {"CLK_MUX_STAT_MFC", CLK_MUX_STAT_MFC, 0x00000111}, + {"CLK_MUX_STAT_G3D", CLK_MUX_STAT_G3D, 0x00000111}, + {"CLK_MUX_STAT_IMAGE", CLK_MUX_STAT_IMAGE, 0x00000111}, + {"CLK_DIV_TOP", CLK_DIV_TOP, 0x00000000}, + {"CLK_DIV_CAM", CLK_DIV_CAM, 0x00000000}, + {"CLK_DIV_TV", CLK_DIV_TV, 0x00000000}, + {"CLK_DIV_MFC", CLK_DIV_MFC, 0x00000000}, + {"CLK_DIV_G3D", CLK_DIV_G3D, 0x00000000}, + {"CLK_DIV_IMAGE", CLK_DIV_IMAGE, 0x00000000}, + {"CLK_DIV_LCD0", CLK_DIV_LCD0, 0x00700000}, + {"CLK_DIV_LCD1", CLK_DIV_LCD1, 0x00700000}, + {"CLK_DIV_MAUDIO", CLK_DIV_MAUDIO, 0x00000000}, + {"CLK_DIV_FSYS0", CLK_DIV_FSYS0, 0x00B00000}, + {"CLK_DIV_FSYS1", CLK_DIV_FSYS1, 0x00000000}, + {"CLK_DIV_FSYS2", CLK_DIV_FSYS2, 0x00000000}, + {"CLK_DIV_FSYS3", CLK_DIV_FSYS3, 0x00000000}, + {"CLK_DIV_PERIL0", CLK_DIV_PERIL0, 0x00000000}, + {"CLK_DIV_PERIL1", CLK_DIV_PERIL1, 0x00000000}, + {"CLK_DIV_PERIL2", CLK_DIV_PERIL2, 0x00000000}, + {"CLK_DIV_PERIL3", CLK_DIV_PERIL3, 0x00000000}, + {"CLK_DIV_PERIL4", CLK_DIV_PERIL4, 0x00000000}, + {"CLK_DIV_PERIL5", CLK_DIV_PERIL5, 0x00000000}, + {"CLKDIV2_RATIO", CLKDIV2_RATIO, 0x11111111}, + {"CLK_DIV_STAT_TOP", CLK_DIV_STAT_TOP, 0x00000000}, + {"CLK_DIV_STAT_CAM", CLK_DIV_STAT_CAM, 0x00000000}, + {"CLK_DIV_STAT_TV", CLK_DIV_STAT_TV, 0x00000000}, + {"CLK_DIV_STAT_MFC", CLK_DIV_STAT_MFC, 0x00000000}, + {"CLK_DIV_STAT_G3D", CLK_DIV_STAT_G3D, 0x00000000}, + {"CLK_DIV_STAT_IMAGE", CLK_DIV_STAT_IMAGE, 0x00000000}, + {"CLK_DIV_STAT_LCD0", CLK_DIV_STAT_LCD0, 0x00000000}, + {"CLK_DIV_STAT_LCD1", CLK_DIV_STAT_LCD1, 0x00000000}, + {"CLK_DIV_STAT_MAUDIO", CLK_DIV_STAT_MAUDIO, 0x00000000}, + {"CLK_DIV_STAT_FSYS0", CLK_DIV_STAT_FSYS0, 0x00000000}, + {"CLK_DIV_STAT_FSYS1", CLK_DIV_STAT_FSYS1, 0x00000000}, + {"CLK_DIV_STAT_FSYS2", CLK_DIV_STAT_FSYS2, 0x00000000}, + {"CLK_DIV_STAT_FSYS3", CLK_DIV_STAT_FSYS3, 0x00000000}, + {"CLK_DIV_STAT_PERIL0", CLK_DIV_STAT_PERIL0, 0x00000000}, + {"CLK_DIV_STAT_PERIL1", CLK_DIV_STAT_PERIL1, 0x00000000}, + {"CLK_DIV_STAT_PERIL2", CLK_DIV_STAT_PERIL2, 0x00000000}, + {"CLK_DIV_STAT_PERIL3", CLK_DIV_STAT_PERIL3, 0x00000000}, + {"CLK_DIV_STAT_PERIL4", CLK_DIV_STAT_PERIL4, 0x00000000}, + {"CLK_DIV_STAT_PERIL5", CLK_DIV_STAT_PERIL5, 0x00000000}, + {"CLKDIV2_STAT", CLKDIV2_STAT, 0x00000000}, + {"CLK_GATE_SCLK_CAM", CLK_GATE_SCLK_CAM, 0xFFFFFFFF}, + {"CLK_GATE_IP_CAM", CLK_GATE_IP_CAM, 0xFFFFFFFF}, + {"CLK_GATE_IP_TV", CLK_GATE_IP_TV, 0xFFFFFFFF}, + {"CLK_GATE_IP_MFC", CLK_GATE_IP_MFC, 0xFFFFFFFF}, + {"CLK_GATE_IP_G3D", CLK_GATE_IP_G3D, 0xFFFFFFFF}, + {"CLK_GATE_IP_IMAGE", CLK_GATE_IP_IMAGE, 0xFFFFFFFF}, + {"CLK_GATE_IP_LCD0", CLK_GATE_IP_LCD0, 0xFFFFFFFF}, + {"CLK_GATE_IP_LCD1", CLK_GATE_IP_LCD1, 0xFFFFFFFF}, + {"CLK_GATE_IP_FSYS", CLK_GATE_IP_FSYS, 0xFFFFFFFF}, + {"CLK_GATE_IP_GPS", CLK_GATE_IP_GPS, 0xFFFFFFFF}, + {"CLK_GATE_IP_PERIL", CLK_GATE_IP_PERIL, 0xFFFFFFFF}, + {"CLK_GATE_IP_PERIR", CLK_GATE_IP_PERIR, 0xFFFFFFFF}, + {"CLK_GATE_BLOCK", CLK_GATE_BLOCK, 0xFFFFFFFF}, + {"CLKOUT_CMU_TOP", CLKOUT_CMU_TOP, 0x00010000}, + {"CLKOUT_CMU_TOP_DIV_STAT", CLKOUT_CMU_TOP_DIV_STAT, 0x00000000}, + /* CMU_DMC registers */ + {"CLK_SRC_DMC", CLK_SRC_DMC, 0x00010000}, + {"CLK_SRC_MASK_DMC", CLK_SRC_MASK_DMC, 0x00010000}, + {"CLK_MUX_STAT_DMC", CLK_MUX_STAT_DMC, 0x11100110}, + {"CLK_DIV_DMC0", CLK_DIV_DMC0, 0x00000000}, + {"CLK_DIV_DMC1", CLK_DIV_DMC1, 0x00000000}, + {"CLK_DIV_STAT_DMC0", CLK_DIV_STAT_DMC0, 0x00000000}, + {"CLK_DIV_STAT_DMC1", CLK_DIV_STAT_DMC1, 0x00000000}, + {"CLK_GATE_IP_DMC", CLK_GATE_IP_DMC, 0xFFFFFFFF}, + {"CLKOUT_CMU_DMC", CLKOUT_CMU_DMC, 0x00010000}, + {"CLKOUT_CMU_DMC_DIV_STAT", CLKOUT_CMU_DMC_DIV_STAT, 0x00000000}, + {"DCGIDX_MAP0", DCGIDX_MAP0, 0xFFFFFFFF}, + {"DCGIDX_MAP1", DCGIDX_MAP1, 0xFFFFFFFF}, + {"DCGIDX_MAP2", DCGIDX_MAP2, 0xFFFFFFFF}, + {"DCGPERF_MAP0", DCGPERF_MAP0, 0xFFFFFFFF}, + {"DCGPERF_MAP1", DCGPERF_MAP1, 0xFFFFFFFF}, + {"DVCIDX_MAP", DVCIDX_MAP, 0xFFFFFFFF}, + {"FREQ_CPU", FREQ_CPU, 0x00000000}, + {"FREQ_DPM", FREQ_DPM, 0x00000000}, + {"DVSEMCLK_EN", DVSEMCLK_EN, 0x00000000}, + {"MAXPERF", MAXPERF, 0x00000000}, + {"APLL_LOCK", APLL_LOCK, 0x00000FFF}, + {"MPLL_LOCK", MPLL_LOCK, 0x00000FFF}, + {"APLL_CON0", APLL_CON0, 0x00C80601}, + {"APLL_CON1", APLL_CON1, 0x0000001C}, + {"MPLL_CON0", MPLL_CON0, 0x00C80601}, + {"MPLL_CON1", MPLL_CON1, 0x0000001C}, + /* CMU_CPU registers */ + {"CLK_SRC_CPU", CLK_SRC_CPU, 0x00000000}, + {"CLK_MUX_STAT_CPU", CLK_MUX_STAT_CPU, 0x00110101}, + {"CLK_DIV_CPU0", CLK_DIV_CPU0, 0x00000000}, + {"CLK_DIV_CPU1", CLK_DIV_CPU1, 0x00000000}, + {"CLK_DIV_STAT_CPU0", CLK_DIV_STAT_CPU0, 0x00000000}, + {"CLK_DIV_STAT_CPU1", CLK_DIV_STAT_CPU1, 0x00000000}, + {"CLK_GATE_SCLK_CPU", CLK_GATE_SCLK_CPU, 0xFFFFFFFF}, + {"CLK_GATE_IP_CPU", CLK_GATE_IP_CPU, 0xFFFFFFFF}, + {"CLKOUT_CMU_CPU", CLKOUT_CMU_CPU, 0x00010000}, + {"CLKOUT_CMU_CPU_DIV_STAT", CLKOUT_CMU_CPU_DIV_STAT, 0x00000000}, + {"ARMCLK_STOPCTRL", ARMCLK_STOPCTRL, 0x00000044}, + {"ATCLK_STOPCTRL", ATCLK_STOPCTRL, 0x00000044}, + {"PARITYFAIL_STATUS", PARITYFAIL_STATUS, 0x00000000}, + {"PARITYFAIL_CLEAR", PARITYFAIL_CLEAR, 0x00000000}, + {"PWR_CTRL", PWR_CTRL, 0x00000033}, + {"APLL_CON0_L8", APLL_CON0_L8, 0x00C80601}, + {"APLL_CON0_L7", APLL_CON0_L7, 0x00C80601}, + {"APLL_CON0_L6", APLL_CON0_L6, 0x00C80601}, + {"APLL_CON0_L5", APLL_CON0_L5, 0x00C80601}, + {"APLL_CON0_L4", APLL_CON0_L4, 0x00C80601}, + {"APLL_CON0_L3", APLL_CON0_L3, 0x00C80601}, + {"APLL_CON0_L2", APLL_CON0_L2, 0x00C80601}, + {"APLL_CON0_L1", APLL_CON0_L1, 0x00C80601}, + {"IEM_CONTROL", IEM_CONTROL, 0x00000000}, + {"APLL_CON1_L8", APLL_CON1_L8, 0x00000000}, + {"APLL_CON1_L7", APLL_CON1_L7, 0x00000000}, + {"APLL_CON1_L6", APLL_CON1_L6, 0x00000000}, + {"APLL_CON1_L5", APLL_CON1_L5, 0x00000000}, + {"APLL_CON1_L4", APLL_CON1_L4, 0x00000000}, + {"APLL_CON1_L3", APLL_CON1_L3, 0x00000000}, + {"APLL_CON1_L2", APLL_CON1_L2, 0x00000000}, + {"APLL_CON1_L1", APLL_CON1_L1, 0x00000000}, + {"CLKDIV_IEM_L8", CLKDIV_IEM_L8, 0x00000000}, + {"CLKDIV_IEM_L7", CLKDIV_IEM_L7, 0x00000000}, + {"CLKDIV_IEM_L6", CLKDIV_IEM_L6, 0x00000000}, + {"CLKDIV_IEM_L5", CLKDIV_IEM_L5, 0x00000000}, + {"CLKDIV_IEM_L4", CLKDIV_IEM_L4, 0x00000000}, + {"CLKDIV_IEM_L3", CLKDIV_IEM_L3, 0x00000000}, + {"CLKDIV_IEM_L2", CLKDIV_IEM_L2, 0x00000000}, + {"CLKDIV_IEM_L1", CLKDIV_IEM_L1, 0x00000000}, +}; + + +/* +* There are five CMUs: +* +* CMU_LEFTBUS +* CMU_RIGHTBUS +* CMU_TOP
hw/exynos4210_cmu.c line 452
Quoted 10 lines
hw/exynos4210_cmu.c new file +10
-0+* CMU_DMC +* CMU_CPU +* +* each of them uses 16KB address space for SFRs +* +* + 0x4000 because SFR region for CMUs starts at 0x10030000, +* but the first CMU (CMU_LEFTBUS) starts with this offset +* +*/ +#define EXYNOS4210_CMU_REGS_MEM_SIZE (0x4000 * 5 + 0x4000)
It seems a bit unlikely to me that there's really a single indivisble bit of hardware with 23 kilobytes worth of register area. Is there a better way of structuring this so that there are a number of sub-memory-regions that cover this space each with their own read/write functions (and perhaps with their own state structs)? (eg instantiate five CPUs at the right locations.)
Quoted 118 lines
hw/exynos4210_cmu.c new file +118
-0+ +/* +* for indexing register in the uint32_t array +* +* 'reg' - register offset (see offsets definitions above) +* +*/ +#define I_ (reg) (reg / sizeof(uint32_t)) + +#define XOM_0 1/* Select XXTI (0) or XUSBXTI (1) base clock source */ + +/* +* Offsets in CLK_SRC_CPU register +* for control MUXMPLL and MUXAPLL +* +* 0 = FINPLL, 1 = MOUTM(A)PLLFOUT +*/ +#define MUX_APLL_SEL_SHIFT 0 +#define MUX_MPLL_SEL_SHIFT 8 +#define MUX_CORE_SEL_SHIFT 16 +#define MUX_HPM_SEL_SHIFT 20 + +#define MUX_APLL_SEL (1 << MUX_APLL_SEL_SHIFT) +#define MUX_MPLL_SEL (1 << MUX_MPLL_SEL_SHIFT) +#define MUX_CORE_SEL (1 << MUX_CORE_SEL_SHIFT) +#define MUX_HPM_SEL (1 << MUX_HPM_SEL_SHIFT) + +/* Offsets for fields in CLK_MUX_STAT_CPU register */ +#define APLL_SEL_SHIFT 0 +#define APLL_SEL_MASK 0x00000007 +#define MPLL_SEL_SHIFT 8 +#define MPLL_SEL_MASK 0x00000700 +#define CORE_SEL_SHIFT 16 +#define CORE_SEL_MASK 0x00070000 +#define HPM_SEL_SHIFT 20 +#define HPM_SEL_MASK 0x00700000 + + +/* Offsets for fields in <pll>_CON0 register */ +#define PLL_ENABLE_SHIFT 31 +#define PLL_ENABLE_MASK 0x80000000/* [31] bit */ +#define PLL_LOCKED_MASK 0x20000000/* [29] bit */ +#define PLL_MDIV_SHIFT 16 +#define PLL_MDIV_MASK 0x03FF0000/* [25:16] bits */ +#define PLL_PDIV_SHIFT 8 +#define PLL_PDIV_MASK 0x00003F00/* [13:8] bits */ +#define PLL_SDIV_SHIFT 0 +#define PLL_SDIV_MASK 0x00000007/* [2:0] bits */ + + + +/* +* Offset in CLK_DIV_CPU0 register +* for DIVAPLL clock divider ratio +*/ +#define APLL_RATIO_SHIFT 24 +#define APLL_RATIO_MASK 0x07000000/* [26:24] bits */ + +/* +* Offset in CLK_DIV_TOP register +* for DIVACLK_100 clock divider ratio +*/ +#define ACLK_100_RATIO_SHIFT 4 +#define ACLK_100_RATIO_MASK 0x000000f0/* [7:4] bits */ + +/* Offset in CLK_SRC_TOP0 register */ +#define MUX_ACLK_100_SEL_SHIFT 16 + +/* +* Offsets in CLK_SRC_PERIL0 register +* for clock sources of UARTs +*/ +#define UART0_SEL_SHIFT 0 +#define UART1_SEL_SHIFT 4 +#define UART2_SEL_SHIFT 8 +#define UART3_SEL_SHIFT 12 +#define UART4_SEL_SHIFT 16 +/* +* Offsets in CLK_DIV_PERIL0 register +* for clock divider of UARTs +*/ +#define UART0_DIV_SHIFT 0 +#define UART1_DIV_SHIFT 4 +#define UART2_DIV_SHIFT 8 +#define UART3_DIV_SHIFT 12 +#define UART4_DIV_SHIFT 16 + +typedef struct { + SysBusDevice busdev; + MemoryRegion iomem; + + uint32_t reg[EXYNOS4210_CMU_REGS_MEM_SIZE]; + +}Exynos4210CmuState ; + +#define SOURCES_NUMBER 9 +#define RECIPIENTS_NUMBER 9 + +typedef struct Exynos4210CmuClockState { + + const char *name; + uint64_t rate; + + /* Current source clock */ + struct Exynos4210CmuClockState *source; + /* + * Available sources. Their order must correspond to CLK_SRC_ register + */ + struct Exynos4210CmuClockState *sources[SOURCES_NUMBER]; + /* Who uses this clock? */ + struct Exynos4210CmuClockState *recipients[RECIPIENTS_NUMBER]; + + uint32_t src_reg; /* Offset of CLK_SRC_<*> register */ + uint32_t div_reg; /* Offset of CLK_DIV_<*> register */ + + /* + * Shift for MUX_<clk>_SEL value which is stored + * in appropriate CLK_MUX_STAT_<cmu> register
hw/exynos4210_cmu.c line 580
Quoted 10 lines
hw/exynos4210_cmu.c new file +10
-0+*/ + uint8_t mux_shift; + + /* + * Shift for <clk>_RATIO value which is stored + * in appropriate CLK_DIV_<cmu> register + */ + uint8_t div_shift; + +} Exynos4210CmuClockState;
So, how does this compare with the struct clk in hw/omap_clk.c ? Is there a useful generalisation we can make rather than having every SOC model doing its own thing for clock trees?
Quoted 121 lines
hw/exynos4210_cmu.c new file +121
-0+ +/* Clocks from Clock Pads */ + +/* It should be used only for testing purposes. XOM_0 is 0 */ +static Exynos4210CmuClockState xxti = { + .name = "XXTI", + .rate = 24000000, +}; + +/* Main source. XOM_0 is 1 */ +static Exynos4210CmuClockState xusbxti = { + .name = "XUSBXTI", + .rate = 24000000, +}; + +/* PLLs */ + +static Exynos4210CmuClockState mpll = { + .name = "MPLL", + .source = (XOM_0 ? &xusbxti : &xxti), +}; + +static Exynos4210CmuClockState apll = { + .name = "APLL", + .source = (XOM_0 ? &xusbxti : &xxti), +}; + + +/**/ +static Exynos4210CmuClockState sclk_mpll = { + .name = "SCLK_MPLL", + .sources = {XOM_0 ? &xusbxti : &xxti, &mpll}, + .src_reg = CLK_SRC_CPU, + .mux_shift = MUX_MPLL_SEL_SHIFT, +}; + +static Exynos4210CmuClockState sclk_apll = { + .name = "SCLK_APLL", + .sources = {XOM_0 ? &xusbxti : &xxti, &apll}, + .src_reg = CLK_SRC_CPU, + .div_reg = CLK_DIV_CPU0, + .mux_shift = MUX_APLL_SEL_SHIFT, + .div_shift = APLL_RATIO_SHIFT, +}; + +static Exynos4210CmuClockState aclk_100 = { + .name = "ACLK_100", + .sources = {&sclk_mpll, &sclk_apll}, + .src_reg = CLK_SRC_TOP0, + .div_reg = CLK_DIV_TOP, + .mux_shift = MUX_ACLK_100_SEL_SHIFT, + .div_shift = ACLK_100_RATIO_SHIFT, +}; + + +/* TODO: add other needed structures for UARTs sources */ +static Exynos4210CmuClockState sclk_uart0 = { + .name = "SCLK_UART0", + .sources = {&xxti, &xusbxti, NULL, NULL, NULL, NULL, &sclk_mpll}, + .src_reg = CLK_SRC_PERIL0, + .div_reg = CLK_DIV_PERIL0, + .mux_shift = UART0_SEL_SHIFT, + .div_shift = UART0_DIV_SHIFT, +}; + +static Exynos4210CmuClockState sclk_uart1 = { + .name = "SCLK_UART1", + .sources = {&xxti, &xusbxti, NULL, NULL, NULL, NULL, &sclk_mpll}, + .src_reg = CLK_SRC_PERIL0, + .div_reg = CLK_DIV_PERIL0, + .mux_shift = UART1_SEL_SHIFT, + .div_shift = UART1_DIV_SHIFT, +}; + +static Exynos4210CmuClockState sclk_uart2 = { + .name = "SCLK_UART2", + .sources = {&xxti, &xusbxti, NULL, NULL, NULL, NULL, &sclk_mpll}, + .src_reg = CLK_SRC_PERIL0, + .div_reg = CLK_DIV_PERIL0, + .mux_shift = UART2_SEL_SHIFT, + .div_shift = UART2_DIV_SHIFT, +}; + +static Exynos4210CmuClockState sclk_uart3 = { + .name = "SCLK_UART3", + .sources = {&xxti, &xusbxti, NULL, NULL, NULL, NULL, &sclk_mpll}, + .src_reg = CLK_SRC_PERIL0, + .div_reg = CLK_DIV_PERIL0, + .mux_shift = UART3_SEL_SHIFT, + .div_shift = UART3_DIV_SHIFT, +}; + +static Exynos4210CmuClockState sclk_uart4 = { + .name = "SCLK_UART4", + .sources = {&xxti, &xusbxti, NULL, NULL, NULL, NULL, &sclk_mpll}, + .src_reg = CLK_SRC_PERIL0, + .div_reg = CLK_DIV_PERIL0, + .mux_shift = UART4_SEL_SHIFT, + .div_shift = UART4_DIV_SHIFT, +}; + +/* +* This array must correspond to Exynos4210CmuClock enumerator +* which is defined in exynos4210.h file +* +*/ +static Exynos4210CmuClockState *exynos4210_clock[] = { + &xxti, + &xusbxti, + &apll, + &mpll, + &sclk_apll, + &sclk_mpll, + &aclk_100, + &sclk_uart0, + &sclk_uart1, + &sclk_uart2, + &sclk_uart3, + &sclk_uart4, + NULL +};
hw/exynos4210_cmu.c line 712
Quoted 10 lines
hw/exynos4210_cmu.c new file +10
-0+ + +uint64_t exynos4210_cmu_get_rate (Exynos4210CmuClock clock) +{ + return exynos4210_clock[clock]->rate; +} + +#ifdef DEBUG_CMU +/* The only meaning of life - debugging. This functions should be only used +* inside PRINT_DEBUG_... macroses
"This function".
"macros".
hw/exynos4210_cmu.c line 717
Quoted 5 lines
hw/exynos4210_cmu.c new file +5
-0+*/ +static const char *exynos4210_cmu_regname(target_phys_addr_t offset) +{ + + int regs_number = sizeof(exynos4210_cmu_regs)/sizeof(Exynos4210CmuReg);
int regs_number = ARRAY_SIZE(exynos4210_cmu_regs);
Quoted 142 lines
hw/exynos4210_cmu.c new file +142
-0+ int i; + + for (i = 0; i < regs_number; i++) { + if (offset == exynos4210_cmu_regs[i].offset) { + return exynos4210_cmu_regs[i].name; + } + } + + return NULL; +} +#endif + +static void exynos4210_cmu_set_pll (void *opaque,target_phys_addr_t offset) +{ + Exynos4210CmuState *s = (Exynos4210CmuState *)opaque; + uint32_t pdiv, mdiv, sdiv, enable; + + /* + * FOUT = MDIV * FIN / (PDIV * 2^(SDIV-1)) + */ + + enable = (s->reg[I_(offset)] & PLL_ENABLE_MASK) >> PLL_ENABLE_SHIFT; + mdiv = (s->reg[I_(offset)] & PLL_MDIV_MASK) >> PLL_MDIV_SHIFT; + pdiv = (s->reg[I_(offset)] & PLL_PDIV_MASK) >> PLL_PDIV_SHIFT; + sdiv = (s->reg[I_(offset)] & PLL_SDIV_MASK) >> PLL_SDIV_SHIFT; + + switch (offset) { + + case MPLL_CON0: + if (mpll.source) { + if (enable) { + mpll.rate = mdiv * mpll.source->rate / (pdiv * (1 << (sdiv-1))); + } else { + mpll.rate = 0; + } + } else { + hw_error("exynos4210_cmu_set_pll: Source undefined for %s\n", + mpll.name); + } + PRINT_DEBUG("mpll.rate: %llu\n", (unsigned long long int)mpll.rate); + break; + + case APLL_CON0: + if (apll.source) { + if (enable) { + apll.rate = mdiv * apll.source->rate / (pdiv * (1 << (sdiv-1))); + } else { + apll.rate = 0; + } + } else { + hw_error("exynos4210_cmu_set_pll: Source undefined for %s\n", + apll.name); + } + PRINT_DEBUG("apll.rate: %llu\n", (unsigned long long int)apll.rate); + break; + + default: + hw_error("exynos4210_cmu_set_pll: Bad offset 0x%x\n", (int)offset); + } + + s->reg[I_(offset)] |= PLL_LOCKED_MASK; +} + + +static void +exynos4210_cmu_set_rate (void *opaque,Exynos4210CmuClockState *clock) +{ + Exynos4210CmuState *s = (Exynos4210CmuState *)opaque; + int i; + + /* Rates of PLLs are calculated differently than ordinary clocks rates */ + if (clock == &mpll) { + exynos4210_cmu_set_pll(s, MPLL_CON0); + } else if (clock == &apll) { + exynos4210_cmu_set_pll(s, APLL_CON0); + } else if ((clock != &xxti) && (clock != &xusbxti)) { + /* + * Not root clock. We don't need calculating rate + * of root clock because it is hard coded. + */ + uint32_t src_index = I_(clock->src_reg); + uint32_t div_index = I_(clock->div_reg); + clock->source = clock->sources[(s->reg[src_index] >> + clock->mux_shift) & 0xf]; + clock->rate = muldiv64(clock->source->rate, 1, + (((s->reg[div_index] >> clock->div_shift) & 0xf) + + 1)); + + PRINT_DEBUG_EXTEND("SRC: <0x%05x> %s, SHIFT: %d\n", + clock->src_reg, + exynos4210_cmu_regname(clock->src_reg), + clock->mux_shift); + + PRINT_DEBUG("%s [%s:%llu]: %llu\n", + clock->name, + clock->source->name, + (uint64_t)clock->source->rate, + (uint64_t)clock->rate); + } + + /* Visit all recipients for given clock */ + i = 0; + do { + + Exynos4210CmuClockState *recipient_clock = clock->recipients[i]; + + if (recipient_clock == NULL) { + PRINT_DEBUG_EXTEND("%s have %d recipients\n", clock->name, i); + break; + } + + uint32_t src_index = recipient_clock->src_reg / sizeof(uint32_t); + int source_index = s->reg[src_index] >> + recipient_clock->mux_shift & 0xf; + recipient_clock->source = recipient_clock->sources[source_index]; + + if (recipient_clock->source != clock) { + break; + } + + exynos4210_cmu_set_rate(s, recipient_clock); + + i++; + } while (i < RECIPIENTS_NUMBER); +} + + +static uint64_t exynos4210_cmu_read (void *opaque,target_phys_addr_t offset, + unsigned size) +{ + Exynos4210CmuState *s = (Exynos4210CmuState *)opaque; + + if (offset > (EXYNOS4210_CMU_REGS_MEM_SIZE - sizeof(uint32_t))) { + hw_error("exynos4210_cmu_read: Bad offset 0x%x\n", (int)offset); + } + + PRINT_DEBUG_EXTEND("<0x%05x> %s -> %08x\n", offset, + exynos4210_cmu_regname(offset), s->reg[I_(offset)]); + + return s->reg[I_(offset)]; +} +
hw/exynos4210_cmu.c line 869
Quoted 10 lines
hw/exynos4210_cmu.c new file +10
-0+ +static void exynos4210_cmu_write (void *opaque,target_phys_addr_t offset, + uint64_t val, unsigned size) +{ + Exynos4210CmuState *s = (Exynos4210CmuState *)opaque; + uint32_t pre_val; + + if (offset > (EXYNOS4210_CMU_REGS_MEM_SIZE - sizeof(uint32_t))) { + hw_error("exynos4210_cmu_write: Bad offset 0x%x\n", (int)offset); + }
General rule: don't hw_error() for things a guest can trigger, like writing to bogus offsets in a device.
Quoted 134 lines
hw/exynos4210_cmu.c new file +134
-0+ + pre_val = s->reg[I_(offset)]; + s->reg[I_(offset)] = val; + + PRINT_DEBUG_EXTEND("<0x%05x> %s <- %08x\n", offset, + exynos4210_cmu_regname(offset), s->reg[I_(offset)]); + + switch (offset) { + + case APLL_CON0: + val = (val & ~PLL_LOCKED_MASK) | (pre_val & PLL_LOCKED_MASK); + s->reg[I_(offset)] = val; + exynos4210_cmu_set_rate(s, &apll); + break; + case MPLL_CON0: + val = (val & ~PLL_LOCKED_MASK) | (pre_val & PLL_LOCKED_MASK); + s->reg[I_(offset)] = val; + exynos4210_cmu_set_rate(s, &mpll); + break; + case CLK_SRC_CPU: + { + if (val & MUX_APLL_SEL) { + s->reg[I_(CLK_MUX_STAT_CPU)] = + (s->reg[I_(CLK_MUX_STAT_CPU)] & ~(APLL_SEL_MASK)) | + (2 << APLL_SEL_SHIFT); + + if ((pre_val & MUX_APLL_SEL) != + (s->reg[I_(offset)] & MUX_APLL_SEL)) { + exynos4210_cmu_set_rate(s, &apll); + } + + } else { + s->reg[I_(CLK_MUX_STAT_CPU)] = + (s->reg[I_(CLK_MUX_STAT_CPU)] & ~(APLL_SEL_MASK)) | + (1 << APLL_SEL_SHIFT); + + if ((pre_val & MUX_APLL_SEL) != + (s->reg[I_(offset)] & MUX_APLL_SEL)) { + exynos4210_cmu_set_rate(s, XOM_0 ? &xusbxti : &xxti); + } + } + + + if (val & MUX_MPLL_SEL) { + s->reg[I_(CLK_MUX_STAT_CPU)] = + (s->reg[I_(CLK_MUX_STAT_CPU)] & ~(MPLL_SEL_MASK)) | + (2 << MPLL_SEL_SHIFT); + + if ((pre_val & MUX_MPLL_SEL) != + (s->reg[I_(offset)] & MUX_MPLL_SEL)) { + exynos4210_cmu_set_rate(s, &mpll); + } + + } else { + s->reg[I_(CLK_MUX_STAT_CPU)] = + (s->reg[I_(CLK_MUX_STAT_CPU)] & ~(MPLL_SEL_MASK)) | + (1 << MPLL_SEL_SHIFT); + + if ((pre_val & MUX_MPLL_SEL) != + (s->reg[I_(offset)] & MUX_MPLL_SEL)) { + exynos4210_cmu_set_rate(s, XOM_0 ? &xusbxti : &xxti); + } + } + + if (val & MUX_CORE_SEL) { + s->reg[I_(CLK_MUX_STAT_CPU)] = + (s->reg[I_(CLK_MUX_STAT_CPU)] & ~(CORE_SEL_MASK)) | + (2 << CORE_SEL_SHIFT); + + if ((pre_val & MUX_CORE_SEL) != + (s->reg[I_(offset)] & MUX_CORE_SEL)) { + exynos4210_cmu_set_rate(s, &sclk_mpll); + } + + } else { + s->reg[I_(CLK_MUX_STAT_CPU)] = + (s->reg[I_(CLK_MUX_STAT_CPU)] & ~(CORE_SEL_MASK)) | + (1 << CORE_SEL_SHIFT); + + if ((pre_val & MUX_CORE_SEL) != + (s->reg[I_(offset)] & MUX_CORE_SEL)) { + exynos4210_cmu_set_rate(s, XOM_0 ? &xusbxti : &xxti); + } + } + + if (val & MUX_HPM_SEL) { + exynos4210_cmu_set_rate(s, &sclk_mpll); + s->reg[I_(CLK_MUX_STAT_CPU)] = + (s->reg[I_(CLK_MUX_STAT_CPU)] & ~(HPM_SEL_MASK)) | + (2 << HPM_SEL_SHIFT); + + if ((pre_val & MUX_HPM_SEL) != (s->reg[I_(offset)] & MUX_HPM_SEL)) { + exynos4210_cmu_set_rate(s, &sclk_mpll); + } + + } else { + s->reg[I_(CLK_MUX_STAT_CPU)] = + (s->reg[I_(CLK_MUX_STAT_CPU)] & ~(HPM_SEL_MASK)) | + (1 << HPM_SEL_SHIFT); + + if ((pre_val & MUX_HPM_SEL) != (s->reg[I_(offset)] & MUX_HPM_SEL)) { + exynos4210_cmu_set_rate(s, XOM_0 ? &xusbxti : &xxti); + } + } + } + break; + case CLK_DIV_CPU0: + exynos4210_cmu_set_rate(s, &sclk_apll); + exynos4210_cmu_set_rate(s, &sclk_mpll); + break; + case CLK_SRC_TOP0: + case CLK_DIV_TOP: + exynos4210_cmu_set_rate(s, &aclk_100); + break; + default: + break; + } +} + + +static const MemoryRegionOps exynos4210_cmu_ops = { + .read = exynos4210_cmu_read, + .write = exynos4210_cmu_write, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + + +static void exynos4210_cmu_reset (void *opaque) +{ + Exynos4210CmuState *s = (Exynos4210CmuState *)opaque; + int i = 0, j = 0, n = 0; + int regs_number = sizeof(exynos4210_cmu_regs)/sizeof(Exynos4210CmuReg); + uint32_t index = 0; +
hw/exynos4210_cmu.c line 1013
Quoted 10 lines
hw/exynos4210_cmu.c new file +10
-0+ /* Set default values for registers */ + for (i = 0; i < regs_number; i++) { + index = (exynos4210_cmu_regs[i].offset) / sizeof(uint32_t); + s->reg[index] = exynos4210_cmu_regs[i].reset_value; + } + + /* clear recipients array from previous reset */ + for (i = 0; i < CLOCKS_NUMBER; i++) { + bzero(exynos4210_clock[i]->recipients, + RECIPIENTS_NUMBER * sizeof(Exynos4210CmuClockState *));
bzero() is deprecated. Use memset().
Quoted 55 lines
hw/exynos4210_cmu.c new file +55
-0+ } + + /* + * Here we fill '.recipients' fields in all clocks. Also we fill empty + * 'sources[]' arrays by values of 'source' fields (it is necessary + * for set rate, for example). If 'sources[]' array and 'source' field + * is empty simultaneously we get hw_error. + * + */ + for (i = 0; i < CLOCKS_NUMBER; i++) { + + /* visit all clocks in the exynos4210_clock */ + + PRINT_DEBUG("[SOURCES] %s: ", exynos4210_clock[i]->name); + + j = 0; + do { /* visit all sources for current clock (exynos4210_clock[i]) */ + + if ((exynos4210_clock[i]->sources[j] == NULL)) { + + if (j == 0) { /* check if we have empty '.sources[]' array */ + if (exynos4210_clock[i]->source != NULL) { + exynos4210_clock[i]->sources[j] = + exynos4210_clock[i]->source; + } else { + /* + * We haven't any defined sources for this clock. Error + * during definition of appropriate clock structure + * + */ + if ((exynos4210_clock[i] != &xusbxti) && + (exynos4210_clock[i] != &xxti)) { + + hw_error("exynos4210_cmu_reset:" + "There aren't any sources for %s clock!\n", + exynos4210_clock[i]->name); + } else { + /* + * we don't need any sources for this clock + * because it's a root clock + */ + break; + } + } + } else { + break; /* leave because there are no more sources */ + } + + } + + PRINT_DEBUG_SIMPLE(" %s", exynos4210_clock[i]->sources[j]->name); + + /* + * find first empty place in 'recipients[]' array of + * current 'sources' element and put current clock there
hw/exynos4210_cmu.c line 1078
Quoted 10 lines
hw/exynos4210_cmu.c new file +10
-0+*/ + n = 0; + do { + if ((exynos4210_clock[i]->sources[j]->recipients[n]) == NULL) { + exynos4210_clock[i]->sources[j]->recipients[n] = + exynos4210_clock[i]; + break; + } + n++; + } while (n < RECIPIENTS_NUMBER);
What's wrong with "for (n = 0; n < RECIPIENTS_NUMBER; n++)" ? (Ditto the loop with j, for that matter.)
Quoted 24 lines
hw/exynos4210_cmu.c new file +24
-0+ + j++; + + } while (j < SOURCES_NUMBER); + + PRINT_DEBUG_SIMPLE("\n"); + + } /* CLOCKS_NUMBER */ + +#ifdef DEBUG_CMU + for (i = 0; i < CLOCKS_NUMBER; i++) { + PRINT_DEBUG("[RECIPIENTS] %s: ", exynos4210_clock[i]->name); + for (j = 0; + (j < RECIPIENTS_NUMBER) && + ((exynos4210_clock[i]->recipients[j]) != NULL); + j++) { + PRINT_DEBUG_SIMPLE("%s ", exynos4210_clock[i]->recipients[j]->name); + } + PRINT_DEBUG_SIMPLE("\n"); + } +#endif + + exynos4210_cmu_set_rate(s, XOM_0 ? &xusbxti : &xxti); +}
hw/exynos4210_cmu.c line 1112
Quoted 10 lines
hw/exynos4210_cmu.c new file +10
-0+ +static const VMStateDescription vmstate_exynos4210_cmu = { + .name = "exynos4210.cmu", + .version_id = 1, + .minimum_version_id = 1, + .minimum_version_id_old = 1, + .fields = (VMStateField[]) { + /* + * TODO: Maybe we should save Exynos4210CmuClockState structs as well + */
If there's anything in them that can change at runtime (as opposed to being statically determined at board init time) then yes, it needs to be saved/restored.
Quoted 8 lines
hw/exynos4210_cmu.c new file +8
-0+ VMSTATE_UINT32_ARRAY(reg, Exynos4210CmuState, + EXYNOS4210_CMU_REGS_MEM_SIZE), + VMSTATE_END_OF_LIST() + } +}; + +static int exynos4210_cmu_init (SysBusDevice *dev) +{
hw/exynos4210_cmu.c line 1130
Quoted 10 lines
hw/exynos4210_cmu.c new file +10
-0+ Exynos4210CmuState *s = FROM_SYSBUS(Exynos4210CmuState, dev); + + /* memory mapping */ + memory_region_init_io(&s->iomem, &exynos4210_cmu_ops, s, "exynos4210.cmu", + EXYNOS4210_CMU_REGS_MEM_SIZE); + sysbus_init_mmio(dev, &s->iomem); + + qemu_register_reset(exynos4210_cmu_reset, s); + + vmstate_register(&dev->qdev, -1, &vmstate_exynos4210_cmu, s);
If you use sysbus_register_withprop() rather than sysbus_register_dev() you can pass the VMState and reset functions as .qdev.vmsd and .qdev.reset fields in the SysBusDeviceInfo struct.
hw/exynos4210_cmu.c line 1132
Quoted 2 lines
hw/exynos4210_cmu.c new file +2
-0+ + exynos4210_cmu_reset(s);
You don't need to explicitly call reset here, qdev will do it for you.
Quoted 18 lines
hw/exynos4210_cmu.c new file +14
-1+ + return 0; +} + + +static void exynos4210_cmu_register (void ) +{ + sysbus_register_dev("exynos4210.cmu", + sizeof(Exynos4210CmuState), + exynos4210_cmu_init); +} + + +device_init (exynos4210_cmu_register) --1.7.4.1
Re: [Qemu-devel] [PATCH v3 02/14] ARM: exynos4210: CMU support
Quoted 6 lines
Quoted 6 lines
hw/exynos4210_cmu.c new file +6
-0+ +static const VMStateDescription vmstate_exynos4210_cmu = { + .name ="exynos4210.cmu" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 ,
Quoted 9 lines
hw/exynos4210_cmu.c line 1112
Quoted 4 lines
hw/exynos4210_cmu.c new file +4
-0+ .fields = (VMStateField[]) { +/* +* TODO: Maybe we should save Exynos4210CmuClockState structs as well +*/ If there's anything in them that can change at runtime (as opposed to being statically determined at board init time) then yes, it needs to be saved/restored.
Should we save globally defined static structures , some fields of which can be changed at runtime? If yes, could you recommend a right way to do that?
Re: [Qemu-devel] [PATCH v3 02/14] ARM: exynos4210: CMU support
Quoted 2 lines · Maksim E. Kozlov
Should we save globally defined static structures , some fields of which can be changed at runtime? If yes, could you recommend a right way to do that?
You shouldn't have globally defined static structures or variables which can be changed at runtime. That would mean you couldn't instantiate two of whichever qdev device that state belonged to. (For the current exynos obviously you wouldn't have two clock trees, but in future QEMU might be improved to support instantiating two board models at once.)
-- PMM
Re: [Qemu-devel] [PATCH v3 02/14] ARM: exynos4210: CMU support
In reply to Peter MaydellQuoted 16 lines
Quoted 16 lines
hw/exynos4210_cmu.c new file +16
-0+ +/* +* There are five CMUs: +* +* CMU_LEFTBUS +* CMU_RIGHTBUS +* CMU_TOP +* CMU_DMC +* CMU_CPU +* +* each of them uses 16KB address space for SFRs +* +* + 0x4000 because SFR region for CMUs starts at 0x10030000, +* but the first CMU (CMU_LEFTBUS) starts with this offset +* +*/
Quoted 9 lines
Quoted 1 line
+#define
EXYNOS4210_CMU_REGS_MEM_SIZE(0x4000* 5 +0x4000)It seems a bit unlikely to me that there's really a single indivisble bit of hardware with 23 kilobytes worth of register area. Is there a better way of structuring this so that there are a number of sub-memory-regions that cover this space each with their own read/write functions (and perhaps with their own state structs)? (eg instantiate five CPUs at the right locations.)
Dear Peter,
Sorry, but I don't quite understand what do you mean. Which 23 kilobytes you have in mind?
And what benefits we get from division whole region into some sub-regions? Current approach seems quite simple and clear. Isn't it?
Re: [Qemu-devel] [PATCH v3 02/14] ARM: exynos4210: CMU support
Quoted 27 lines · Maksim E. Kozlov
Quoted 19 lines
Quoted 7 lines
hw/exynos4210_cmu.c new file +7
-0+ +/* +* There are five CMUs: +* +* CMU_LEFTBUS +* CMU_RIGHTBUS +* CMU_TOP hw/exynos4210_cmu.c line 452
Quoted 10 lines
hw/exynos4210_cmu.c new file +10
-0+* CMU_DMC +* CMU_CPU +* +* each of them uses 16KB address space for SFRs +* +* + 0x4000 because SFR region for CMUs starts at 0x10030000, +* but the first CMU (CMU_LEFTBUS) starts with this offset +* +*/ +#define EXYNOS4210_CMU_REGS_MEM_SIZE (0x4000 * 5 + 0x4000)Quoted 7 lines
It seems a bit unlikely to me that there's really a single indivisble bit of hardware with 23 kilobytes worth of register area. Is there a better way of structuring this so that there are a number of sub-memory-regions that cover this space each with their own read/write functions (and perhaps with their own state structs)? (eg instantiate five CPUs at the right locations.)
Quoted 4 lines
Dear Peter,
Sorry, but I don't quite understand what do you mean. Which 23 kilobytes you have in mind?
This:
+ memory_region_init_io(&s->iomem, &exynos4210_cmu_ops, s, "exynos4210.cmu",
+ EXYNOS4210_CMU_REGS_MEM_SIZE);
defines a single enormous register region EXYNOS4210_CMU_REGS_MEM_SIZE bytes long. The IO functions then implement half a dozen actual registers and let the rest just read/write to a huge array.
Quoted 2 lines
And what benefits we get from division whole region into some sub-regions? Current approach seems quite simple and clear. Isn't it?
The hardware docs say:
"There are five CMUs, i.e., CMU_LEFTBUS, CMU_RIGHTBUS, CMU_TOP, CMU_DMC, and CMU_CPU, in Exynos4210" and "The internal structure of the address space for each CMU is same for all CMUs". Then there are a bunch of different subregions within a CMU, most of which don't have very many actual registers.
This strongly suggests that we should be modelling things in the same way, ie you have one device per CMU (possibly 5 instantiations of the same device if it really is the same thing in each place).
Having "every memory location we don't implement is just reading/writing an array" just seems very unlikely to be how the hardware actually works:
typically there's a set of registers which are at definite locations, and if there are gaps between those registers they might read-as-zero or they might fault, but they won't read-as-written.
-- PMM
Re: [Qemu-devel] [PATCH v3 02/14] ARM: exynos4210: CMU support
In reply to Peter MaydellDear Peter,
Quoted 3 lines
So, how does this compare with the struct clk in
hw/omap_clk.c? Is there a useful generalisation we can make rather than having every SOC model doing its own thing for clock trees?
It's definitely good approach to make similar things in one place, but existing TI Omap clocks model is too different (both hardware and API) to be used in Exynos SoC and refactoring of Omap model is out of our project scope.
For now Exynos CMU is used only for optional UART support so we could just replace it with constant frequencies in components. What is your opinion - cut CMU or keep it as base for some future functionality development?
Thanks,
Dmitry Solodkiy,
Mobile SW PL, Advanced Software Group,
Moscow R&D center, Samsung Electronics
-----Original Message-----
From: Peter Maydell [mailto:[email protected]]
Sent: Tuesday, December 13, 2011 2:45 AM
To: Evgeny Voevodin
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [Qemu-devel] [PATCH v3 02/14] ARM: exynos4210: CMU support
Quoted 530 lines · Evgeny Voevodin
From: Maksim Kozlov <[email protected]>
Add exynos4210 Clock Management Units emulation
Signed-off-by Evgeny Voevodin <[email protected]>--- Makefile.target | 2 +- hw/exynos4210.c | 7 + hw/exynos4210.h | 22 + hw/exynos4210_cmu.c | 1146 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 1176 insertions(+), 1 deletions(-) create mode 100644 hw/exynos4210_cmu.cMakefile.target +1
-1@@ -344,7 +344,7 @@ obj-arm-y = integratorcp.o versatilepb.o arm_pic.o arm_timer.o obj-arm-y += arm_boot.o pl011.o pl031.o pl050.o pl080.o pl110.o pl181.o pl190.o obj-arm-y += versatile_pci.o obj-arm-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.o -obj-arm-y += exynos4210.o +obj-arm-y += exynos4210.o exynos4210_cmu.o obj-arm-y += armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o obj-arm-y += pl061.o obj-arm-y += arm-semi.ohw/exynos4210.c +7
-0@@ -60,6 +60,10 @@#define EXYNOS4210_BASE_BOOT_ADDR EXYNOS4210_DRAM0_BASE_ADDR +/* SFR Base Address for CMUs */ +#define EXYNOS4210_CMU_BASE_ADDR 0x10030000 + +static struct arm_boot_info exynos4210_binfo = { .loader_start =EXYNOS4210_BASE_BOOT_ADDR , };@@ -172,6 +176,9 @@ static void exynos4210_init(ram_addr_t ram_size,memory_region_add_subregion (system_mem,EXYNOS4210_DRAM0_BASE_ADDR , dram0_mem); +/* CMU */ +sysbus_create_simple ("exynos4210.cmu" ,EXYNOS4210_CMU_BASE_ADDR ,NULL ); +/*** Load kernel ***/ exynos4210_binfo.ram_size = ram_size;hw/exynos4210.h +22
-0@@ -31,4 +31,26 @@#define EXYNOS4210_MAX_CPUS 2 +/* +* Interface for exynos4210 Clock Management Units (CMUs) +*/ + +typedef enum { +XXTI , +XUSBXTI , +APLL , +MPLL , +SCLK_APLL , +SCLK_MPLL , +ACLK_100 , +SCLK_UART0 , +SCLK_UART1 , +SCLK_UART2 , +SCLK_UART3 , +SCLK_UART4 , +CLOCKS_NUMBER +}Exynos4210CmuClock ; + +uint64_t exynos4210_cmu_get_rate (Exynos4210CmuClock clock); +#endif /* EXYNOS4210_H_ */ hw/exynos4210_cmu.c new file +442
-0@@ -0,0 +1,1146 @@ +/* +* exynos4210 Clock Management Units (CMUs) Emulation +* +* Copyright (C) 2011 Samsung Electronics Co Ltd. +* Maksim Kozlov, <[email protected]> +* +* Created on: 07.2011 +* +* +* 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, write to the Free Software Foundation, Inc., 51 +* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* +*/ + +#include "sysbus.h" + +#include "exynos4210.h" + + + +#undef DEBUG_CMU + +//#define DEBUG_CMU +//#define DEBUG_CMU_EXTEND + + +#define PRINT_DEBUG(fmt, args...) \ + do {} while (0) +#define PRINT_DEBUG_SIMPLE(fmt, args...) \ + do {} while (0) +#define PRINT_DEBUG_EXTEND(fmt, args...) \ + do {} while (0) +#define PRINT_ERROR(fmt, args...) \ + do { \ + fprintf(stderr, " [%s:%d] "fmt, __func__, __LINE__, ##args); \ + } while (0) + + +#ifdef DEBUG_CMU + +#undef PRINT_DEBUG + #define PRINT_DEBUG(fmt, args...) \ + do { \ + fprintf(stderr, " [%s:%d] "fmt, __func__, __LINE__, ##args); \ + } while (0) + +#undef PRINT_DEBUG_SIMPLE + #define PRINT_DEBUG_SIMPLE(fmt, args...) \ + do { \ + fprintf(stderr, fmt, ## args); \ + } while (0) + +#ifdef DEBUG_CMU_EXTEND + +#undef PRINT_DEBUG_EXTEND + #define PRINT_DEBUG_EXTEND(fmt, args...) \ + do { \ + fprintf(stderr, " [%s:%d] "fmt, __func__, __LINE__, ##args); \ + } while (0) + +#endif /* EXTEND */ +#endif + + +/* +* Offsets for CMUs registers +*/ + +/* CMU_LEFTBUS registers */ +#define CLK_SRC_LEFTBUS 0x04200 +#define CLK_MUX_STAT_LEFTBUS 0x04400 +#define CLK_DIV_LEFTBUS 0x04500 +#define CLK_DIV_STAT_LEFTBUS 0x04600 +#define CLK_GATE_IP_LEFTBUS 0x04800 +#define CLKOUT_CMU_LEFTBUS 0x04A00 +#define CLKOUT_CMU_LEFTBUS_DIV_STAT 0x04A04 +/* CMU_RIGHTBUS registers */ +#define CLK_SRC_RIGHTBUS 0x08200 +#define CLK_MUX_STAT_RIGHTBUS 0x08400 +#define CLK_DIV_RIGHTBUS 0x08500 +#define CLK_DIV_STAT_RIGHTBUS 0x08600 +#define CLK_GATE_IP_RIGHTBUS 0x08800 +#define CLKOUT_CMU_RIGHTBUS 0x08A00 +#define CLKOUT_CMU_RIGHTBUS_DIV_STAT 0x08A04 +/* CMU_TOP registers */ +#define EPLL_LOCK 0x0C010 +#define VPLL_LOCK 0x0C020 +#define EPLL_CON0 0x0C110 +#define EPLL_CON1 0x0C114 +#define VPLL_CON0 0x0C120 +#define VPLL_CON1 0x0C124 +#define CLK_SRC_TOP0 0x0C210 +#define CLK_SRC_TOP1 0x0C214 +#define CLK_SRC_CAM 0x0C220 +#define CLK_SRC_TV 0x0C224 +#define CLK_SRC_MFC 0x0C228 +#define CLK_SRC_G3D 0x0C22C +#define CLK_SRC_IMAGE 0x0C230 +#define CLK_SRC_LCD0 0x0C234 +#define CLK_SRC_LCD1 0x0C238 +#define CLK_SRC_MAUDIO 0x0C23C +#define CLK_SRC_FSYS 0x0C240 +#define CLK_SRC_PERIL0 0x0C250 +#define CLK_SRC_PERIL1 0x0C254 +#define CLK_SRC_MASK_TOP 0x0C310 +#define CLK_SRC_MASK_CAM 0x0C320 +#define CLK_SRC_MASK_TV 0x0C324 +#define CLK_SRC_MASK_LCD0 0x0C334 +#define CLK_SRC_MASK_LCD1 0x0C338 +#define CLK_SRC_MASK_MAUDIO 0x0C33C +#define CLK_SRC_MASK_FSYS 0x0C340 +#define CLK_SRC_MASK_PERIL0 0x0C350 +#define CLK_SRC_MASK_PERIL1 0x0C354 +#define CLK_MUX_STAT_TOP 0x0C410 +#define CLK_MUX_STAT_MFC 0x0C428 +#define CLK_MUX_STAT_G3D 0x0C42C +#define CLK_MUX_STAT_IMAGE 0x0C430 +#define CLK_DIV_TOP 0x0C510 +#define CLK_DIV_CAM 0x0C520 +#define CLK_DIV_TV 0x0C524 +#define CLK_DIV_MFC 0x0C528 +#define CLK_DIV_G3D 0x0C52C +#define CLK_DIV_IMAGE 0x0C530 +#define CLK_DIV_LCD0 0x0C534 +#define CLK_DIV_LCD1 0x0C538 +#define CLK_DIV_MAUDIO 0x0C53C +#define CLK_DIV_FSYS0 0x0C540 +#define CLK_DIV_FSYS1 0x0C544 +#define CLK_DIV_FSYS2 0x0C548 +#define CLK_DIV_FSYS3 0x0C54C +#define CLK_DIV_PERIL0 0x0C550 +#define CLK_DIV_PERIL1 0x0C554 +#define CLK_DIV_PERIL2 0x0C558 +#define CLK_DIV_PERIL3 0x0C55C +#define CLK_DIV_PERIL4 0x0C560 +#define CLK_DIV_PERIL5 0x0C564 +#define CLKDIV2_RATIO 0x0C580 +#define CLK_DIV_STAT_TOP 0x0C610 +#define CLK_DIV_STAT_CAM 0x0C620 +#define CLK_DIV_STAT_TV 0x0C624 +#define CLK_DIV_STAT_MFC 0x0C628 +#define CLK_DIV_STAT_G3D 0x0C62C +#define CLK_DIV_STAT_IMAGE 0x0C630 +#define CLK_DIV_STAT_LCD0 0x0C634 +#define CLK_DIV_STAT_LCD1 0x0C638 +#define CLK_DIV_STAT_MAUDIO 0x0C63C +#define CLK_DIV_STAT_FSYS0 0x0C640 +#define CLK_DIV_STAT_FSYS1 0x0C644 +#define CLK_DIV_STAT_FSYS2 0x0C648 +#define CLK_DIV_STAT_FSYS3 0x0C64C +#define CLK_DIV_STAT_PERIL0 0x0C650 +#define CLK_DIV_STAT_PERIL1 0x0C654 +#define CLK_DIV_STAT_PERIL2 0x0C658 +#define CLK_DIV_STAT_PERIL3 0x0C65C +#define CLK_DIV_STAT_PERIL4 0x0C660 +#define CLK_DIV_STAT_PERIL5 0x0C664 +#define CLKDIV2_STAT 0x0C680 +#define CLK_GATE_SCLK_CAM 0x0C820 +#define CLK_GATE_IP_CAM 0x0C920 +#define CLK_GATE_IP_TV 0x0C924 +#define CLK_GATE_IP_MFC 0x0C928 +#define CLK_GATE_IP_G3D 0x0C92C +#define CLK_GATE_IP_IMAGE 0x0C930 +#define CLK_GATE_IP_LCD0 0x0C934 +#define CLK_GATE_IP_LCD1 0x0C938 +#define CLK_GATE_IP_FSYS 0x0C940 +#define CLK_GATE_IP_GPS 0x0C94C +#define CLK_GATE_IP_PERIL 0x0C950 +#define CLK_GATE_IP_PERIR 0x0C960 +#define CLK_GATE_BLOCK 0x0C970 +#define CLKOUT_CMU_TOP 0x0CA00 +#define CLKOUT_CMU_TOP_DIV_STAT 0x0CA04 +/* CMU_DMC registers */ +#define CLK_SRC_DMC 0x10200 +#define CLK_SRC_MASK_DMC 0x10300 +#define CLK_MUX_STAT_DMC 0x10400 +#define CLK_DIV_DMC0 0x10500 +#define CLK_DIV_DMC1 0x10504 +#define CLK_DIV_STAT_DMC0 0x10600 +#define CLK_DIV_STAT_DMC1 0x10604 +#define CLK_GATE_IP_DMC 0x10900 +#define CLKOUT_CMU_DMC 0x10A00 +#define CLKOUT_CMU_DMC_DIV_STAT 0x10A04 +#define DCGIDX_MAP0 0x11000 +#define DCGIDX_MAP1 0x11004 +#define DCGIDX_MAP2 0x11008 +#define DCGPERF_MAP0 0x11020 +#define DCGPERF_MAP1 0x11024 +#define DVCIDX_MAP 0x11040 +#define FREQ_CPU 0x11060 +#define FREQ_DPM 0x11064 +#define DVSEMCLK_EN 0x11080 +#define MAXPERF 0x11084 +#define APLL_LOCK 0x14000 +#define MPLL_LOCK 0x14008 +#define APLL_CON0 0x14100 +#define APLL_CON1 0x14104 +#define MPLL_CON0 0x14108 +#define MPLL_CON1 0x1410C +/* CMU_CPU registers */ +#define CLK_SRC_CPU 0x14200 +#define CLK_MUX_STAT_CPU 0x14400 +#define CLK_DIV_CPU0 0x14500 +#define CLK_DIV_CPU1 0x14504 +#define CLK_DIV_STAT_CPU0 0x14600 +#define CLK_DIV_STAT_CPU1 0x14604 +#define CLK_GATE_SCLK_CPU 0x14800 +#define CLK_GATE_IP_CPU 0x14900 +#define CLKOUT_CMU_CPU 0x14A00 +#define CLKOUT_CMU_CPU_DIV_STAT 0x14A04 +#define ARMCLK_STOPCTRL 0x15000 +#define ATCLK_STOPCTRL 0x15004 +#define PARITYFAIL_STATUS 0x15010 +#define PARITYFAIL_CLEAR 0x15014 +#define PWR_CTRL 0x15020 +#define APLL_CON0_L8 0x15100 +#define APLL_CON0_L7 0x15104 +#define APLL_CON0_L6 0x15108 +#define APLL_CON0_L5 0x1510C +#define APLL_CON0_L4 0x15110 +#define APLL_CON0_L3 0x15114 +#define APLL_CON0_L2 0x15118 +#define APLL_CON0_L1 0x1511C +#define IEM_CONTROL 0x15120 +#define APLL_CON1_L8 0x15200 +#define APLL_CON1_L7 0x15204 +#define APLL_CON1_L6 0x15208 +#define APLL_CON1_L5 0x1520C +#define APLL_CON1_L4 0x15210 +#define APLL_CON1_L3 0x15214 +#define APLL_CON1_L2 0x15218 +#define APLL_CON1_L1 0x1521C +#define CLKDIV_IEM_L8 0x15300 +#define CLKDIV_IEM_L7 0x15304 +#define CLKDIV_IEM_L6 0x15308 +#define CLKDIV_IEM_L5 0x1530C +#define CLKDIV_IEM_L4 0x15310 +#define CLKDIV_IEM_L3 0x15314 +#define CLKDIV_IEM_L2 0x15318 +#define CLKDIV_IEM_L1 0x1531C + + +typedef struct Exynos4210CmuReg { +const char *name;/* for debugging */ +uint32_t offset; +uint32_t reset_value; +}Exynos4210CmuReg ; + + +static Exynos4210CmuReg exynos4210_cmu_regs[] = { +/* CMU_LEFTBUS registers */ + {"CLK_SRC_LEFTBUS" ,CLK_SRC_LEFTBUS ,0x00000000 }, + {"CLK_MUX_STAT_LEFTBUS" ,CLK_MUX_STAT_LEFTBUS ,0x00000001 }, + {"CLK_DIV_LEFTBUS" ,CLK_DIV_LEFTBUS ,0x00000000 }, + {"CLK_DIV_STAT_LEFTBUS" ,CLK_DIV_STAT_LEFTBUS ,0x00000000 }, + {"CLK_GATE_IP_LEFTBUS" ,CLK_GATE_IP_LEFTBUS ,0xFFFFFFFF }, + {"CLKOUT_CMU_LEFTBUS" ,CLKOUT_CMU_LEFTBUS ,0x00010000 }, + {"CLKOUT_CMU_LEFTBUS_DIV_STAT" ,CLKOUT_CMU_LEFTBUS_DIV_STAT ,0x00000000 }, +/* CMU_RIGHTBUS registers */ + {"CLK_SRC_RIGHTBUS" ,CLK_SRC_RIGHTBUS ,0x00000000 }, + {"CLK_MUX_STAT_RIGHTBUS" ,CLK_MUX_STAT_RIGHTBUS ,0x00000001 }, + {"CLK_DIV_RIGHTBUS" ,CLK_DIV_RIGHTBUS ,0x00000000 }, + {"CLK_DIV_STAT_RIGHTBUS" ,CLK_DIV_STAT_RIGHTBUS ,0x00000000 }, + {"CLK_GATE_IP_RIGHTBUS" ,CLK_GATE_IP_RIGHTBUS ,0xFFFFFFFF }, + {"CLKOUT_CMU_RIGHTBUS" ,CLKOUT_CMU_RIGHTBUS ,0x00010000 }, + {"CLKOUT_CMU_RIGHTBUS_DIV_STAT" ,CLKOUT_CMU_RIGHTBUS_DIV_STAT ,0x00000000 }, +/* CMU_TOP registers */ + {"EPLL_LOCK" ,EPLL_LOCK ,0x00000FFF }, + {"VPLL_LOCK" ,VPLL_LOCK ,0x00000FFF }, + {"EPLL_CON0" ,EPLL_CON0 ,0x00300301 }, + {"EPLL_CON1" ,EPLL_CON1 ,0x00000000 }, + {"VPLL_CON0" ,VPLL_CON0 ,0x00240201 }, + {"VPLL_CON1" ,VPLL_CON1 ,0x66010464 }, + {"CLK_SRC_TOP0" ,CLK_SRC_TOP0 ,0x00000000 }, + {"CLK_SRC_TOP1" ,CLK_SRC_TOP1 ,0x00000000 }, + {"CLK_SRC_CAM" ,CLK_SRC_CAM ,0x11111111 }, + {"CLK_SRC_TV" ,CLK_SRC_TV ,0x00000000 }, + {"CLK_SRC_MFC" ,CLK_SRC_MFC ,0x00000000 }, + {"CLK_SRC_G3D" ,CLK_SRC_G3D ,0x00000000 }, + {"CLK_SRC_IMAGE" ,CLK_SRC_IMAGE ,0x00000000 }, + {"CLK_SRC_LCD0" ,CLK_SRC_LCD0 ,0x00001111 }, + {"CLK_SRC_LCD1" ,CLK_SRC_LCD1 ,0x00001111 }, + {"CLK_SRC_MAUDIO" ,CLK_SRC_MAUDIO ,0x00000005 }, + {"CLK_SRC_FSYS" ,CLK_SRC_FSYS ,0x00011111 }, + {"CLK_SRC_PERIL0" ,CLK_SRC_PERIL0 ,0x00011111 }, + {"CLK_SRC_PERIL1" ,CLK_SRC_PERIL1 ,0x01110055 }, + {"CLK_SRC_MASK_TOP" ,CLK_SRC_MASK_TOP ,0x00000001 }, + {"CLK_SRC_MASK_CAM" ,CLK_SRC_MASK_CAM ,0x11111111 }, + {"CLK_SRC_MASK_TV" ,CLK_SRC_MASK_TV ,0x00000111 }, + {"CLK_SRC_MASK_LCD0" ,CLK_SRC_MASK_LCD0 ,0x00001111 }, + {"CLK_SRC_MASK_LCD1" ,CLK_SRC_MASK_LCD1 ,0x00001111 }, + {"CLK_SRC_MASK_MAUDIO" ,CLK_SRC_MASK_MAUDIO ,0x00000001 }, + {"CLK_SRC_MASK_FSYS" ,CLK_SRC_MASK_FSYS ,0x01011111 }, + {"CLK_SRC_MASK_PERIL0" ,CLK_SRC_MASK_PERIL0 ,0x00011111 }, + {"CLK_SRC_MASK_PERIL1" ,CLK_SRC_MASK_PERIL1 ,0x01110111 }, + {"CLK_MUX_STAT_TOP" ,CLK_MUX_STAT_TOP ,0x11111111 }, + {"CLK_MUX_STAT_MFC" ,CLK_MUX_STAT_MFC ,0x00000111 }, + {"CLK_MUX_STAT_G3D" ,CLK_MUX_STAT_G3D ,0x00000111 }, + {"CLK_MUX_STAT_IMAGE" ,CLK_MUX_STAT_IMAGE ,0x00000111 }, + {"CLK_DIV_TOP" ,CLK_DIV_TOP ,0x00000000 }, + {"CLK_DIV_CAM" ,CLK_DIV_CAM ,0x00000000 }, + {"CLK_DIV_TV" ,CLK_DIV_TV ,0x00000000 }, + {"CLK_DIV_MFC" ,CLK_DIV_MFC ,0x00000000 }, + {"CLK_DIV_G3D" ,CLK_DIV_G3D ,0x00000000 }, + {"CLK_DIV_IMAGE" ,CLK_DIV_IMAGE ,0x00000000 }, + {"CLK_DIV_LCD0" ,CLK_DIV_LCD0 ,0x00700000 }, + {"CLK_DIV_LCD1" ,CLK_DIV_LCD1 ,0x00700000 }, + {"CLK_DIV_MAUDIO" ,CLK_DIV_MAUDIO ,0x00000000 }, + {"CLK_DIV_FSYS0" ,CLK_DIV_FSYS0 ,0x00B00000 }, + {"CLK_DIV_FSYS1" ,CLK_DIV_FSYS1 ,0x00000000 }, + {"CLK_DIV_FSYS2" ,CLK_DIV_FSYS2 ,0x00000000 }, + {"CLK_DIV_FSYS3" ,CLK_DIV_FSYS3 ,0x00000000 }, + {"CLK_DIV_PERIL0" ,CLK_DIV_PERIL0 ,0x00000000 }, + {"CLK_DIV_PERIL1" ,CLK_DIV_PERIL1 ,0x00000000 }, + {"CLK_DIV_PERIL2" ,CLK_DIV_PERIL2 ,0x00000000 }, + {"CLK_DIV_PERIL3" ,CLK_DIV_PERIL3 ,0x00000000 }, + {"CLK_DIV_PERIL4" ,CLK_DIV_PERIL4 ,0x00000000 }, + {"CLK_DIV_PERIL5" ,CLK_DIV_PERIL5 ,0x00000000 }, + {"CLKDIV2_RATIO" ,CLKDIV2_RATIO ,0x11111111 }, + {"CLK_DIV_STAT_TOP" ,CLK_DIV_STAT_TOP ,0x00000000 }, + {"CLK_DIV_STAT_CAM" ,CLK_DIV_STAT_CAM ,0x00000000 }, + {"CLK_DIV_STAT_TV" ,CLK_DIV_STAT_TV ,0x00000000 }, + {"CLK_DIV_STAT_MFC" ,CLK_DIV_STAT_MFC ,0x00000000 }, + {"CLK_DIV_STAT_G3D" ,CLK_DIV_STAT_G3D ,0x00000000 }, + {"CLK_DIV_STAT_IMAGE" ,CLK_DIV_STAT_IMAGE ,0x00000000 }, + {"CLK_DIV_STAT_LCD0" ,CLK_DIV_STAT_LCD0 ,0x00000000 }, + {"CLK_DIV_STAT_LCD1" ,CLK_DIV_STAT_LCD1 ,0x00000000 }, + {"CLK_DIV_STAT_MAUDIO" ,CLK_DIV_STAT_MAUDIO ,0x00000000 }, + {"CLK_DIV_STAT_FSYS0" ,CLK_DIV_STAT_FSYS0 ,0x00000000 }, + {"CLK_DIV_STAT_FSYS1" ,CLK_DIV_STAT_FSYS1 ,0x00000000 }, + {"CLK_DIV_STAT_FSYS2" ,CLK_DIV_STAT_FSYS2 ,0x00000000 }, + {"CLK_DIV_STAT_FSYS3" ,CLK_DIV_STAT_FSYS3 ,0x00000000 }, + {"CLK_DIV_STAT_PERIL0" ,CLK_DIV_STAT_PERIL0 ,0x00000000 }, + {"CLK_DIV_STAT_PERIL1" ,CLK_DIV_STAT_PERIL1 ,0x00000000 }, + {"CLK_DIV_STAT_PERIL2" ,CLK_DIV_STAT_PERIL2 ,0x00000000 }, + {"CLK_DIV_STAT_PERIL3" ,CLK_DIV_STAT_PERIL3 ,0x00000000 }, + {"CLK_DIV_STAT_PERIL4" ,CLK_DIV_STAT_PERIL4 ,0x00000000 }, + {"CLK_DIV_STAT_PERIL5" ,CLK_DIV_STAT_PERIL5 ,0x00000000 }, + {"CLKDIV2_STAT" ,CLKDIV2_STAT ,0x00000000 }, + {"CLK_GATE_SCLK_CAM" ,CLK_GATE_SCLK_CAM ,0xFFFFFFFF }, + {"CLK_GATE_IP_CAM" ,CLK_GATE_IP_CAM ,0xFFFFFFFF }, + {"CLK_GATE_IP_TV" ,CLK_GATE_IP_TV ,0xFFFFFFFF }, + {"CLK_GATE_IP_MFC" ,CLK_GATE_IP_MFC ,0xFFFFFFFF }, + {"CLK_GATE_IP_G3D" ,CLK_GATE_IP_G3D ,0xFFFFFFFF }, + {"CLK_GATE_IP_IMAGE" ,CLK_GATE_IP_IMAGE ,0xFFFFFFFF }, + {"CLK_GATE_IP_LCD0" ,CLK_GATE_IP_LCD0 ,0xFFFFFFFF }, + {"CLK_GATE_IP_LCD1" ,CLK_GATE_IP_LCD1 ,0xFFFFFFFF }, + {"CLK_GATE_IP_FSYS" ,CLK_GATE_IP_FSYS ,0xFFFFFFFF }, + {"CLK_GATE_IP_GPS" ,CLK_GATE_IP_GPS ,0xFFFFFFFF }, + {"CLK_GATE_IP_PERIL" ,CLK_GATE_IP_PERIL ,0xFFFFFFFF }, + {"CLK_GATE_IP_PERIR" ,CLK_GATE_IP_PERIR ,0xFFFFFFFF }, + {"CLK_GATE_BLOCK" ,CLK_GATE_BLOCK ,0xFFFFFFFF }, + {"CLKOUT_CMU_TOP" ,CLKOUT_CMU_TOP ,0x00010000 }, + {"CLKOUT_CMU_TOP_DIV_STAT" ,CLKOUT_CMU_TOP_DIV_STAT ,0x00000000 }, +/* CMU_DMC registers */ + {"CLK_SRC_DMC" ,CLK_SRC_DMC ,0x00010000 }, + {"CLK_SRC_MASK_DMC" ,CLK_SRC_MASK_DMC ,0x00010000 }, + {"CLK_MUX_STAT_DMC" ,CLK_MUX_STAT_DMC ,0x11100110 }, + {"CLK_DIV_DMC0" ,CLK_DIV_DMC0 ,0x00000000 }, + {"CLK_DIV_DMC1" ,CLK_DIV_DMC1 ,0x00000000 }, + {"CLK_DIV_STAT_DMC0" ,CLK_DIV_STAT_DMC0 ,0x00000000 }, + {"CLK_DIV_STAT_DMC1" ,CLK_DIV_STAT_DMC1 ,0x00000000 }, + {"CLK_GATE_IP_DMC" ,CLK_GATE_IP_DMC ,0xFFFFFFFF }, + {"CLKOUT_CMU_DMC" ,CLKOUT_CMU_DMC ,0x00010000 }, + {"CLKOUT_CMU_DMC_DIV_STAT" ,CLKOUT_CMU_DMC_DIV_STAT ,0x00000000 }, + {"DCGIDX_MAP0" ,DCGIDX_MAP0 ,0xFFFFFFFF }, + {"DCGIDX_MAP1" ,DCGIDX_MAP1 ,0xFFFFFFFF }, + {"DCGIDX_MAP2" ,DCGIDX_MAP2 ,0xFFFFFFFF }, + {"DCGPERF_MAP0" ,DCGPERF_MAP0 ,0xFFFFFFFF }, + {"DCGPERF_MAP1" ,DCGPERF_MAP1 ,0xFFFFFFFF }, + {"DVCIDX_MAP" ,DVCIDX_MAP ,0xFFFFFFFF }, + {"FREQ_CPU" ,FREQ_CPU ,0x00000000 }, + {"FREQ_DPM" ,FREQ_DPM ,0x00000000 }, + {"DVSEMCLK_EN" ,DVSEMCLK_EN ,0x00000000 }, + {"MAXPERF" ,MAXPERF ,0x00000000 }, + {"APLL_LOCK" ,APLL_LOCK ,0x00000FFF }, + {"MPLL_LOCK" ,MPLL_LOCK ,0x00000FFF }, + {"APLL_CON0" ,APLL_CON0 ,0x00C80601 }, + {"APLL_CON1" ,APLL_CON1 ,0x0000001C }, + {"MPLL_CON0" ,MPLL_CON0 ,0x00C80601 }, + {"MPLL_CON1" ,MPLL_CON1 ,0x0000001C }, +/* CMU_CPU registers */ + {"CLK_SRC_CPU" ,CLK_SRC_CPU ,0x00000000 }, + {"CLK_MUX_STAT_CPU" ,CLK_MUX_STAT_CPU ,0x00110101 }, + {"CLK_DIV_CPU0" ,CLK_DIV_CPU0 ,0x00000000 }, + {"CLK_DIV_CPU1" ,CLK_DIV_CPU1 ,0x00000000 }, + {"CLK_DIV_STAT_CPU0" ,CLK_DIV_STAT_CPU0 ,0x00000000 }, + {"CLK_DIV_STAT_CPU1" ,CLK_DIV_STAT_CPU1 ,0x00000000 }, + {"CLK_GATE_SCLK_CPU" ,CLK_GATE_SCLK_CPU ,0xFFFFFFFF }, + {"CLK_GATE_IP_CPU" ,CLK_GATE_IP_CPU ,0xFFFFFFFF }, + {"CLKOUT_CMU_CPU" ,CLKOUT_CMU_CPU ,0x00010000 }, + {"CLKOUT_CMU_CPU_DIV_STAT" ,CLKOUT_CMU_CPU_DIV_STAT ,0x00000000 }, + {"ARMCLK_STOPCTRL" ,ARMCLK_STOPCTRL ,0x00000044 }, + {"ATCLK_STOPCTRL" ,ATCLK_STOPCTRL ,0x00000044 }, + {"PARITYFAIL_STATUS" ,PARITYFAIL_STATUS ,0x00000000 }, + {"PARITYFAIL_CLEAR" ,PARITYFAIL_CLEAR ,0x00000000 }, + {"PWR_CTRL" ,PWR_CTRL ,0x00000033 }, + {"APLL_CON0_L8" ,APLL_CON0_L8 ,0x00C80601 }, + {"APLL_CON0_L7" ,APLL_CON0_L7 ,0x00C80601 }, + {"APLL_CON0_L6" ,APLL_CON0_L6 ,0x00C80601 }, + {"APLL_CON0_L5" ,APLL_CON0_L5 ,0x00C80601 }, + {"APLL_CON0_L4" ,APLL_CON0_L4 ,0x00C80601 }, + {"APLL_CON0_L3" ,APLL_CON0_L3 ,0x00C80601 }, + {"APLL_CON0_L2" ,APLL_CON0_L2 ,0x00C80601 }, + {"APLL_CON0_L1" ,APLL_CON0_L1 ,0x00C80601 }, + {"IEM_CONTROL" ,IEM_CONTROL ,0x00000000 }, + {"APLL_CON1_L8" ,APLL_CON1_L8 ,0x00000000 }, + {"APLL_CON1_L7" ,APLL_CON1_L7 ,0x00000000 }, + {"APLL_CON1_L6" ,APLL_CON1_L6 ,0x00000000 }, + {"APLL_CON1_L5" ,APLL_CON1_L5 ,0x00000000 }, + {"APLL_CON1_L4" ,APLL_CON1_L4 ,0x00000000 }, + {"APLL_CON1_L3" ,APLL_CON1_L3 ,0x00000000 }, + {"APLL_CON1_L2" ,APLL_CON1_L2 ,0x00000000 }, + {"APLL_CON1_L1" ,APLL_CON1_L1 ,0x00000000 }, + {"CLKDIV_IEM_L8" ,CLKDIV_IEM_L8 ,0x00000000 }, + {"CLKDIV_IEM_L7" ,CLKDIV_IEM_L7 ,0x00000000 }, + {"CLKDIV_IEM_L6" ,CLKDIV_IEM_L6 ,0x00000000 }, + {"CLKDIV_IEM_L5" ,CLKDIV_IEM_L5 ,0x00000000 }, + {"CLKDIV_IEM_L4" ,CLKDIV_IEM_L4 ,0x00000000 }, + {"CLKDIV_IEM_L3" ,CLKDIV_IEM_L3 ,0x00000000 }, + {"CLKDIV_IEM_L2" ,CLKDIV_IEM_L2 ,0x00000000 }, + {"CLKDIV_IEM_L1" ,CLKDIV_IEM_L1 ,0x00000000 }, +}; + + +/* +* There are five CMUs: +* +* CMU_LEFTBUS +* CMU_RIGHTBUS +* CMU_TOP
hw/exynos4210_cmu.c line 452
Quoted 10 lines
hw/exynos4210_cmu.c new file +10
-0+* CMU_DMC +* CMU_CPU +* +* each of them uses 16KB address space for SFRs +* +* + 0x4000 because SFR region for CMUs starts at 0x10030000, +* but the first CMU (CMU_LEFTBUS) starts with this offset +* +*/ +#define EXYNOS4210_CMU_REGS_MEM_SIZE (0x4000 * 5 + 0x4000)
It seems a bit unlikely to me that there's really a single indivisble bit of hardware with 23 kilobytes worth of register area. Is there a better way of structuring this so that there are a number of sub-memory-regions that cover this space each with their own read/write functions (and perhaps with their own state structs)? (eg instantiate five CPUs at the right locations.)
Quoted 118 lines
hw/exynos4210_cmu.c new file +118
-0+ +/* +* for indexing register in the uint32_t array +* +* 'reg' - register offset (see offsets definitions above) +* +*/ +#define I_ (reg) (reg / sizeof(uint32_t)) + +#define XOM_0 1/* Select XXTI (0) or XUSBXTI (1) base clock source */ + +/* +* Offsets in CLK_SRC_CPU register +* for control MUXMPLL and MUXAPLL +* +* 0 = FINPLL, 1 = MOUTM(A)PLLFOUT +*/ +#define MUX_APLL_SEL_SHIFT 0 +#define MUX_MPLL_SEL_SHIFT 8 +#define MUX_CORE_SEL_SHIFT 16 +#define MUX_HPM_SEL_SHIFT 20 + +#define MUX_APLL_SEL (1 << MUX_APLL_SEL_SHIFT) +#define MUX_MPLL_SEL (1 << MUX_MPLL_SEL_SHIFT) +#define MUX_CORE_SEL (1 << MUX_CORE_SEL_SHIFT) +#define MUX_HPM_SEL (1 << MUX_HPM_SEL_SHIFT) + +/* Offsets for fields in CLK_MUX_STAT_CPU register */ +#define APLL_SEL_SHIFT 0 +#define APLL_SEL_MASK 0x00000007 +#define MPLL_SEL_SHIFT 8 +#define MPLL_SEL_MASK 0x00000700 +#define CORE_SEL_SHIFT 16 +#define CORE_SEL_MASK 0x00070000 +#define HPM_SEL_SHIFT 20 +#define HPM_SEL_MASK 0x00700000 + + +/* Offsets for fields in <pll>_CON0 register */ +#define PLL_ENABLE_SHIFT 31 +#define PLL_ENABLE_MASK 0x80000000/* [31] bit */ +#define PLL_LOCKED_MASK 0x20000000/* [29] bit */ +#define PLL_MDIV_SHIFT 16 +#define PLL_MDIV_MASK 0x03FF0000/* [25:16] bits */ +#define PLL_PDIV_SHIFT 8 +#define PLL_PDIV_MASK 0x00003F00/* [13:8] bits */ +#define PLL_SDIV_SHIFT 0 +#define PLL_SDIV_MASK 0x00000007/* [2:0] bits */ + + + +/* +* Offset in CLK_DIV_CPU0 register +* for DIVAPLL clock divider ratio +*/ +#define APLL_RATIO_SHIFT 24 +#define APLL_RATIO_MASK 0x07000000/* [26:24] bits */ + +/* +* Offset in CLK_DIV_TOP register +* for DIVACLK_100 clock divider ratio +*/ +#define ACLK_100_RATIO_SHIFT 4 +#define ACLK_100_RATIO_MASK 0x000000f0/* [7:4] bits */ + +/* Offset in CLK_SRC_TOP0 register */ +#define MUX_ACLK_100_SEL_SHIFT 16 + +/* +* Offsets in CLK_SRC_PERIL0 register +* for clock sources of UARTs +*/ +#define UART0_SEL_SHIFT 0 +#define UART1_SEL_SHIFT 4 +#define UART2_SEL_SHIFT 8 +#define UART3_SEL_SHIFT 12 +#define UART4_SEL_SHIFT 16 +/* +* Offsets in CLK_DIV_PERIL0 register +* for clock divider of UARTs +*/ +#define UART0_DIV_SHIFT 0 +#define UART1_DIV_SHIFT 4 +#define UART2_DIV_SHIFT 8 +#define UART3_DIV_SHIFT 12 +#define UART4_DIV_SHIFT 16 + +typedef struct { +SysBusDevice busdev; +MemoryRegion iomem; + +uint32_t reg[EXYNOS4210_CMU_REGS_MEM_SIZE ]; + +}Exynos4210CmuState ; + +#define SOURCES_NUMBER 9 +#define RECIPIENTS_NUMBER 9 + +typedef struct Exynos4210CmuClockState { + + const char *name; + uint64_t rate; + + /* Current source clock */ + struct Exynos4210CmuClockState *source; + /* + * Available sources. Their order must correspond to CLK_SRC_ register + */ + struct Exynos4210CmuClockState *sources[SOURCES_NUMBER]; + /* Who uses this clock? */ + struct Exynos4210CmuClockState *recipients[RECIPIENTS_NUMBER]; + + uint32_t src_reg; /* Offset of CLK_SRC_<*> register */ + uint32_t div_reg; /* Offset of CLK_DIV_<*> register */ + + /* + * Shift for MUX_<clk>_SEL value which is stored + * in appropriate CLK_MUX_STAT_<cmu> register
hw/exynos4210_cmu.c line 580
Quoted 10 lines
hw/exynos4210_cmu.c new file +10
-0+*/ +uint8_t mux_shift; + +/* +* Shift for <clk>_RATIO value which is stored +* in appropriate CLK_DIV_<cmu> register +*/ +uint8_t div_shift; + +} Exynos4210CmuClockState;
So, how does this compare with the struct clk in hw/omap_clk.c ? Is there a useful generalisation we can make rather than having every SOC model doing its own thing for clock trees?
Quoted 121 lines
hw/exynos4210_cmu.c new file +121
-0+ +/* Clocks from Clock Pads */ + +/* It should be used only for testing purposes. XOM_0 is 0 */ +static Exynos4210CmuClockState xxti = { + .name ="XXTI" , + .rate =24000000 , +}; + +/* Main source. XOM_0 is 1 */ +static Exynos4210CmuClockState xusbxti = { + .name ="XUSBXTI" , + .rate =24000000 , +}; + +/* PLLs */ + +static Exynos4210CmuClockState mpll = { + .name ="MPLL" , + .source = (XOM_0 ? &xusbxti : &xxti), +}; + +static Exynos4210CmuClockState apll = { + .name ="APLL" , + .source = (XOM_0 ? &xusbxti : &xxti), +}; + + +/**/ +static Exynos4210CmuClockState sclk_mpll = { + .name ="SCLK_MPLL" , + .sources = {XOM_0 ? &xusbxti : &xxti, &mpll}, + .src_reg =CLK_SRC_CPU , + .mux_shift =MUX_MPLL_SEL_SHIFT , +}; + +static Exynos4210CmuClockState sclk_apll = { + .name ="SCLK_APLL" , + .sources = {XOM_0 ? &xusbxti : &xxti, &apll}, + .src_reg =CLK_SRC_CPU , + .div_reg =CLK_DIV_CPU0 , + .mux_shift =MUX_APLL_SEL_SHIFT , + .div_shift =APLL_RATIO_SHIFT , +}; + +static Exynos4210CmuClockState aclk_100 = { + .name ="ACLK_100" , + .sources = {&sclk_mpll, &sclk_apll}, + .src_reg =CLK_SRC_TOP0 , + .div_reg =CLK_DIV_TOP , + .mux_shift =MUX_ACLK_100_SEL_SHIFT , + .div_shift =ACLK_100_RATIO_SHIFT , +}; + + +/* TODO: add other needed structures for UARTs sources */ +static Exynos4210CmuClockState sclk_uart0 = { + .name ="SCLK_UART0" , + .sources = {&xxti, &xusbxti,NULL ,NULL ,NULL ,NULL , &sclk_mpll}, + .src_reg =CLK_SRC_PERIL0 , + .div_reg =CLK_DIV_PERIL0 , + .mux_shift =UART0_SEL_SHIFT , + .div_shift =UART0_DIV_SHIFT , +}; + +static Exynos4210CmuClockState sclk_uart1 = { + .name ="SCLK_UART1" , + .sources = {&xxti, &xusbxti,NULL ,NULL ,NULL ,NULL , &sclk_mpll}, + .src_reg =CLK_SRC_PERIL0 , + .div_reg =CLK_DIV_PERIL0 , + .mux_shift =UART1_SEL_SHIFT , + .div_shift =UART1_DIV_SHIFT , +}; + +static Exynos4210CmuClockState sclk_uart2 = { + .name ="SCLK_UART2" , + .sources = {&xxti, &xusbxti,NULL ,NULL ,NULL ,NULL , &sclk_mpll}, + .src_reg =CLK_SRC_PERIL0 , + .div_reg =CLK_DIV_PERIL0 , + .mux_shift =UART2_SEL_SHIFT , + .div_shift =UART2_DIV_SHIFT , +}; + +static Exynos4210CmuClockState sclk_uart3 = { + .name ="SCLK_UART3" , + .sources = {&xxti, &xusbxti,NULL ,NULL ,NULL ,NULL , &sclk_mpll}, + .src_reg =CLK_SRC_PERIL0 , + .div_reg =CLK_DIV_PERIL0 , + .mux_shift =UART3_SEL_SHIFT , + .div_shift =UART3_DIV_SHIFT , +}; + +static Exynos4210CmuClockState sclk_uart4 = { + .name ="SCLK_UART4" , + .sources = {&xxti, &xusbxti,NULL ,NULL ,NULL ,NULL , &sclk_mpll}, + .src_reg =CLK_SRC_PERIL0 , + .div_reg =CLK_DIV_PERIL0 , + .mux_shift =UART4_SEL_SHIFT , + .div_shift =UART4_DIV_SHIFT , +}; + +/* +* This array must correspond to Exynos4210CmuClock enumerator +* which is defined in exynos4210.h file +* +*/ +static Exynos4210CmuClockState *exynos4210_clock[] = { + &xxti, + &xusbxti, + &apll, + &mpll, + &sclk_apll, + &sclk_mpll, + &aclk_100, + &sclk_uart0, + &sclk_uart1, + &sclk_uart2, + &sclk_uart3, + &sclk_uart4, +NULL +};
hw/exynos4210_cmu.c line 712
Quoted 10 lines
hw/exynos4210_cmu.c new file +10
-0+ + +uint64_t exynos4210_cmu_get_rate (Exynos4210CmuClock clock) +{ +return exynos4210_clock[clock]->rate; +} + +#ifdef DEBUG_CMU +/* The only meaning of life - debugging. This functions should be only used +* inside PRINT_DEBUG_... macroses
"This function".
"macros".
hw/exynos4210_cmu.c line 717
Quoted 5 lines
hw/exynos4210_cmu.c new file +5
-0+*/ +static const char *exynos4210_cmu_regname (target_phys_addr_t offset) +{ + +int regs_number =sizeof (exynos4210_cmu_regs)/sizeof (Exynos4210CmuReg);
int regs_number = ARRAY_SIZE(exynos4210_cmu_regs);
Quoted 142 lines
hw/exynos4210_cmu.c new file +142
-0+int i; + +for (i =0 ; i < regs_number; i++) { +if (offset == exynos4210_cmu_regs[i].offset) { +return exynos4210_cmu_regs[i].name; + } + } + +return NULL ; +} +#endif + +static void exynos4210_cmu_set_pll (void *opaque,target_phys_addr_t offset) +{ +Exynos4210CmuState *s = (Exynos4210CmuState *)opaque; +uint32_t pdiv, mdiv, sdiv, enable; + +/* +* FOUT = MDIV * FIN / (PDIV * 2^(SDIV-1)) +*/ + + enable = (s->reg[I_ (offset)] &PLL_ENABLE_MASK ) >>PLL_ENABLE_SHIFT ; + mdiv = (s->reg[I_ (offset)] &PLL_MDIV_MASK ) >>PLL_MDIV_SHIFT ; + pdiv = (s->reg[I_ (offset)] &PLL_PDIV_MASK ) >>PLL_PDIV_SHIFT ; + sdiv = (s->reg[I_ (offset)] &PLL_SDIV_MASK ) >>PLL_SDIV_SHIFT ; + +switch (offset) { + +case MPLL_CON0 : +if (mpll.source) { +if (enable) { + mpll.rate = mdiv * mpll.source->rate / (pdiv * (1 << (sdiv-1 ))); + }else { + mpll.rate =0 ; + } + }else { +hw_error ("exynos4210_cmu_set_pll: Source undefined for %s\n" , + mpll.name); + } +PRINT_DEBUG ("mpll.rate: %llu\n" , (unsigned long long int )mpll.rate); +break ; + +case APLL_CON0 : +if (apll.source) { +if (enable) { + apll.rate = mdiv * apll.source->rate / (pdiv * (1 << (sdiv-1 ))); + }else { + apll.rate =0 ; + } + }else { +hw_error ("exynos4210_cmu_set_pll: Source undefined for %s\n" , + apll.name); + } +PRINT_DEBUG ("apll.rate: %llu\n" , (unsigned long long int )apll.rate); +break ; + +default : +hw_error ("exynos4210_cmu_set_pll: Bad offset 0x%x\n" , (int )offset); + } + + s->reg[I_ (offset)] |=PLL_LOCKED_MASK ; +} + + +static void +exynos4210_cmu_set_rate (void *opaque,Exynos4210CmuClockState *clock) +{ +Exynos4210CmuState *s = (Exynos4210CmuState *)opaque; +int i; + +/* Rates of PLLs are calculated differently than ordinary clocks rates */ +if (clock == &mpll) { +exynos4210_cmu_set_pll (s,MPLL_CON0 ); + }else if (clock == &apll) { +exynos4210_cmu_set_pll (s,APLL_CON0 ); + }else if ((clock != &xxti) && (clock != &xusbxti)) { +/* +* Not root clock. We don't need calculating rate +* of root clock because it is hard coded. +*/ +uint32_t src_index =I_ (clock->src_reg); +uint32_t div_index =I_ (clock->div_reg); + clock->source = clock->sources[(s->reg[src_index] >> + clock->mux_shift) &0xf ]; + clock->rate =muldiv64 (clock->source->rate,1 , + (((s->reg[div_index] >> clock->div_shift) &0xf ) + +1 )); + +PRINT_DEBUG_EXTEND ("SRC: <0x%05x> %s, SHIFT: %d\n" , + clock->src_reg, +exynos4210_cmu_regname (clock->src_reg), + clock->mux_shift); + +PRINT_DEBUG ("%s [%s:%llu]: %llu\n" , + clock->name, + clock->source->name, + (uint64_t )clock->source->rate, + (uint64_t )clock->rate); + } + +/* Visit all recipients for given clock */ + i =0 ; +do { + +Exynos4210CmuClockState *recipient_clock = clock->recipients[i]; + +if (recipient_clock ==NULL ) { +PRINT_DEBUG_EXTEND ("%s have %d recipients\n" , clock->name, i); +break ; + } + +uint32_t src_index = recipient_clock->src_reg /sizeof (uint32_t ); +int source_index = s->reg[src_index] >> + recipient_clock->mux_shift &0xf ; + recipient_clock->source = recipient_clock->sources[source_index]; + +if (recipient_clock->source != clock) { +break ; + } + +exynos4210_cmu_set_rate (s, recipient_clock); + + i++; + }while (i <RECIPIENTS_NUMBER ); +} + + +static uint64_t exynos4210_cmu_read (void *opaque,target_phys_addr_t offset, +unsigned size) +{ +Exynos4210CmuState *s = (Exynos4210CmuState *)opaque; + +if (offset > (EXYNOS4210_CMU_REGS_MEM_SIZE -sizeof (uint32_t ))) { +hw_error ("exynos4210_cmu_read: Bad offset 0x%x\n" , (int )offset); + } + +PRINT_DEBUG_EXTEND ("<0x%05x> %s -> %08x\n" , offset, +exynos4210_cmu_regname (offset), s->reg[I_ (offset)]); + +return s->reg[I_ (offset)]; +} +
hw/exynos4210_cmu.c line 869
Quoted 10 lines
hw/exynos4210_cmu.c new file +10
-0+ +static void exynos4210_cmu_write (void *opaque,target_phys_addr_t offset, +uint64_t val,unsigned size) +{ +Exynos4210CmuState *s = (Exynos4210CmuState *)opaque; +uint32_t pre_val; + +if (offset > (EXYNOS4210_CMU_REGS_MEM_SIZE -sizeof (uint32_t ))) { +hw_error ("exynos4210_cmu_write: Bad offset 0x%x\n" , (int )offset); + }
General rule: don't hw_error() for things a guest can trigger, like writing to bogus offsets in a device.
Quoted 134 lines
hw/exynos4210_cmu.c new file +134
-0+ + pre_val = s->reg[I_ (offset)]; + s->reg[I_ (offset)] = val; + +PRINT_DEBUG_EXTEND ("<0x%05x> %s <- %08x\n" , offset, +exynos4210_cmu_regname (offset), s->reg[I_ (offset)]); + +switch (offset) { + +case APLL_CON0 : + val = (val & ~PLL_LOCKED_MASK ) | (pre_val &PLL_LOCKED_MASK ); + s->reg[I_ (offset)] = val; +exynos4210_cmu_set_rate (s, &apll); +break ; +case MPLL_CON0 : + val = (val & ~PLL_LOCKED_MASK ) | (pre_val &PLL_LOCKED_MASK ); + s->reg[I_ (offset)] = val; +exynos4210_cmu_set_rate (s, &mpll); +break ; +case CLK_SRC_CPU : + { +if (val &MUX_APLL_SEL ) { + s->reg[I_ (CLK_MUX_STAT_CPU )] = + (s->reg[I_ (CLK_MUX_STAT_CPU )] & ~(APLL_SEL_MASK )) | + (2 <<APLL_SEL_SHIFT ); + +if ((pre_val &MUX_APLL_SEL ) != + (s->reg[I_ (offset)] &MUX_APLL_SEL )) { +exynos4210_cmu_set_rate (s, &apll); + } + + }else { + s->reg[I_ (CLK_MUX_STAT_CPU )] = + (s->reg[I_ (CLK_MUX_STAT_CPU )] & ~(APLL_SEL_MASK )) | + (1 <<APLL_SEL_SHIFT ); + +if ((pre_val &MUX_APLL_SEL ) != + (s->reg[I_ (offset)] &MUX_APLL_SEL )) { +exynos4210_cmu_set_rate (s,XOM_0 ? &xusbxti : &xxti); + } + } + + +if (val &MUX_MPLL_SEL ) { + s->reg[I_ (CLK_MUX_STAT_CPU )] = + (s->reg[I_ (CLK_MUX_STAT_CPU )] & ~(MPLL_SEL_MASK )) | + (2 <<MPLL_SEL_SHIFT ); + +if ((pre_val &MUX_MPLL_SEL ) != + (s->reg[I_ (offset)] &MUX_MPLL_SEL )) { +exynos4210_cmu_set_rate (s, &mpll); + } + + }else { + s->reg[I_ (CLK_MUX_STAT_CPU )] = + (s->reg[I_ (CLK_MUX_STAT_CPU )] & ~(MPLL_SEL_MASK )) | + (1 <<MPLL_SEL_SHIFT ); + +if ((pre_val &MUX_MPLL_SEL ) != + (s->reg[I_ (offset)] &MUX_MPLL_SEL )) { +exynos4210_cmu_set_rate (s,XOM_0 ? &xusbxti : &xxti); + } + } + +if (val &MUX_CORE_SEL ) { + s->reg[I_ (CLK_MUX_STAT_CPU )] = + (s->reg[I_ (CLK_MUX_STAT_CPU )] & ~(CORE_SEL_MASK )) | + (2 <<CORE_SEL_SHIFT ); + +if ((pre_val &MUX_CORE_SEL ) != + (s->reg[I_ (offset)] &MUX_CORE_SEL )) { +exynos4210_cmu_set_rate (s, &sclk_mpll); + } + + }else { + s->reg[I_ (CLK_MUX_STAT_CPU )] = + (s->reg[I_ (CLK_MUX_STAT_CPU )] & ~(CORE_SEL_MASK )) | + (1 <<CORE_SEL_SHIFT ); + +if ((pre_val &MUX_CORE_SEL ) != + (s->reg[I_ (offset)] &MUX_CORE_SEL )) { +exynos4210_cmu_set_rate (s,XOM_0 ? &xusbxti : &xxti); + } + } + +if (val &MUX_HPM_SEL ) { +exynos4210_cmu_set_rate (s, &sclk_mpll); + s->reg[I_ (CLK_MUX_STAT_CPU )] = + (s->reg[I_ (CLK_MUX_STAT_CPU )] & ~(HPM_SEL_MASK )) | + (2 <<HPM_SEL_SHIFT ); + +if ((pre_val &MUX_HPM_SEL ) != (s->reg[I_ (offset)] &MUX_HPM_SEL )) { +exynos4210_cmu_set_rate (s, &sclk_mpll); + } + + }else { + s->reg[I_ (CLK_MUX_STAT_CPU )] = + (s->reg[I_ (CLK_MUX_STAT_CPU )] & ~(HPM_SEL_MASK )) | + (1 <<HPM_SEL_SHIFT ); + +if ((pre_val &MUX_HPM_SEL ) != (s->reg[I_ (offset)] &MUX_HPM_SEL )) { +exynos4210_cmu_set_rate (s,XOM_0 ? &xusbxti : &xxti); + } + } + } +break ; +case CLK_DIV_CPU0 : +exynos4210_cmu_set_rate (s, &sclk_apll); +exynos4210_cmu_set_rate (s, &sclk_mpll); +break ; +case CLK_SRC_TOP0 : +case CLK_DIV_TOP : +exynos4210_cmu_set_rate (s, &aclk_100); +break ; +default : +break ; + } +} + + +static const MemoryRegionOps exynos4210_cmu_ops = { + .read = exynos4210_cmu_read, + .write = exynos4210_cmu_write, + .endianness =DEVICE_NATIVE_ENDIAN , +}; + + +static void exynos4210_cmu_reset (void *opaque) +{ +Exynos4210CmuState *s = (Exynos4210CmuState *)opaque; +int i =0 , j =0 , n =0 ; +int regs_number =sizeof (exynos4210_cmu_regs)/sizeof (Exynos4210CmuReg); +uint32_t index =0 ; +
hw/exynos4210_cmu.c line 1013
Quoted 10 lines
hw/exynos4210_cmu.c new file +10
-0+/* Set default values for registers */ +for (i =0 ; i < regs_number; i++) { + index = (exynos4210_cmu_regs[i].offset) /sizeof (uint32_t ); + s->reg[index] = exynos4210_cmu_regs[i].reset_value; + } + +/* clear recipients array from previous reset */ +for (i =0 ; i <CLOCKS_NUMBER ; i++) { +bzero (exynos4210_clock[i]->recipients, +RECIPIENTS_NUMBER *sizeof (Exynos4210CmuClockState *));
bzero() is deprecated. Use memset().
Quoted 55 lines
hw/exynos4210_cmu.c new file +55
-0+ } + +/* +* Here we fill '.recipients' fields in all clocks. Also we fill empty +* 'sources[]' arrays by values of 'source' fields (it is necessary +* for set rate, for example). If 'sources[]' array and 'source' field +* is empty simultaneously we get hw_error. +* +*/ +for (i =0 ; i <CLOCKS_NUMBER ; i++) { + +/* visit all clocks in the exynos4210_clock */ + +PRINT_DEBUG ("[SOURCES] %s: " , exynos4210_clock[i]->name); + + j =0 ; + do { /* visit all sources for current clock (exynos4210_clock[i]) */ + + if ((exynos4210_clock[i]->sources[j] == NULL)) { + + if (j == 0) { /* check if we have empty '.sources[]' array */ + if (exynos4210_clock[i]->source != NULL) { + exynos4210_clock[i]->sources[j] = + exynos4210_clock[i]->source; + } else { + /* + * We haven't any defined sources for this clock. Error + * during definition of appropriate clock structure + * + */ + if ((exynos4210_clock[i] != &xusbxti) && + (exynos4210_clock[i] != &xxti)) { + + hw_error("exynos4210_cmu_reset:" + "There aren't any sources for %s clock!\n", + exynos4210_clock[i]->name); + } else { + /* + * we don't need any sources for this clock + * because it's a root clock + */ + break; + } + } + } else { + break; /* leave because there are no more sources */ + } + + } + + PRINT_DEBUG_SIMPLE(" %s", exynos4210_clock[i]->sources[j]->name); + + /* + * find first empty place in 'recipients[]' array of + * current 'sources' element and put current clock there
hw/exynos4210_cmu.c line 1078
Quoted 10 lines
hw/exynos4210_cmu.c new file +10
-0+*/ + n =0 ; +do { +if ((exynos4210_clock[i]->sources[j]->recipients[n]) ==NULL ) { + exynos4210_clock[i]->sources[j]->recipients[n] = + exynos4210_clock[i]; +break ; + } + n++; + }while (n <RECIPIENTS_NUMBER );
What's wrong with "for (n = 0; n < RECIPIENTS_NUMBER; n++)" ? (Ditto the loop with j, for that matter.)
Quoted 24 lines
hw/exynos4210_cmu.c new file +24
-0+ + j++; + + }while (j <SOURCES_NUMBER ); + +PRINT_DEBUG_SIMPLE ("\n" ); + + }/* CLOCKS_NUMBER */ + +#ifdef DEBUG_CMU +for (i =0 ; i <CLOCKS_NUMBER ; i++) { +PRINT_DEBUG ("[RECIPIENTS] %s: " , exynos4210_clock[i]->name); +for (j =0 ; + (j <RECIPIENTS_NUMBER ) && + ((exynos4210_clock[i]->recipients[j]) !=NULL ); + j++) { +PRINT_DEBUG_SIMPLE ("%s " , exynos4210_clock[i]->recipients[j]->name); + } +PRINT_DEBUG_SIMPLE ("\n" ); + } +#endif + +exynos4210_cmu_set_rate (s,XOM_0 ? &xusbxti : &xxti); +}
hw/exynos4210_cmu.c line 1112
Quoted 10 lines
hw/exynos4210_cmu.c new file +10
-0+ +static const VMStateDescription vmstate_exynos4210_cmu = { + .name ="exynos4210.cmu" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +/* +* TODO: Maybe we should save Exynos4210CmuClockState structs as well +*/
If there's anything in them that can change at runtime (as opposed to being statically determined at board init time) then yes, it needs to be saved/restored.
Quoted 8 lines
hw/exynos4210_cmu.c new file +8
-0+VMSTATE_UINT32_ARRAY (reg, Exynos4210CmuState, +EXYNOS4210_CMU_REGS_MEM_SIZE ), + VMSTATE_END_OF_LIST() + } +}; + +static int exynos4210_cmu_init (SysBusDevice *dev) +{
hw/exynos4210_cmu.c line 1130
Quoted 10 lines
hw/exynos4210_cmu.c new file +10
-0+Exynos4210CmuState *s =FROM_SYSBUS (Exynos4210CmuState, dev); + +/* memory mapping */ +memory_region_init_io (&s->iomem, &exynos4210_cmu_ops, s,"exynos4210.cmu" , +EXYNOS4210_CMU_REGS_MEM_SIZE ); +sysbus_init_mmio (dev, &s->iomem); + +qemu_register_reset (exynos4210_cmu_reset, s); + +vmstate_register (&dev->qdev,-1 , &vmstate_exynos4210_cmu, s);
If you use sysbus_register_withprop() rather than sysbus_register_dev() you can pass the VMState and reset functions as .qdev.vmsd and .qdev.reset fields in the SysBusDeviceInfo struct.
hw/exynos4210_cmu.c line 1132
Quoted 2 lines
hw/exynos4210_cmu.c new file +2
-0+ +exynos4210_cmu_reset (s);
You don't need to explicitly call reset here, qdev will do it for you.
Quoted 18 lines
hw/exynos4210_cmu.c new file +14
-1+ +return 0 ; +} + + +static void exynos4210_cmu_register (void ) +{ +sysbus_register_dev ("exynos4210.cmu" , +sizeof (Exynos4210CmuState), + exynos4210_cmu_init); +} + + +device_init (exynos4210_cmu_register) --1.7.4.1
PATCH v3 3/14 ARM: exynos4210: UART support
In reply to Evgeny VoevodinFrom: Maksim Kozlov <[email protected]>
Add basic support of exynos4210 UART
Conflicts:
Makefile.target
--- Makefile.target | 2 +- hw/exynos4210.c | 51 ++++ hw/exynos4210.h | 9 + hw/exynos4210_uart.c | 674 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 735 insertions(+), 1 deletions(-) create mode 100644 hw/exynos4210_uart.c
Makefile.target +1 -1
@@ -344,7 +344,7 @@ obj-arm-y = integratorcp.o versatilepb.o arm_pic.o arm_timer.o obj-arm-y += arm_boot.o pl011.o pl031.o pl050.o pl080.o pl110.o pl181.o pl190.o obj-arm-y += versatile_pci.o obj-arm-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.o -obj-arm-y += exynos4210.o exynos4210_cmu.o +obj-arm-y += exynos4210.o exynos4210_cmu.o exynos4210_uart.o obj-arm-y += armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o obj-arm-y += pl061.o obj-arm-y += arm-semi.o
hw/exynos4210.c +51 -0
63 lines not on this page · raw message
hw/exynos4210.h +9 -0
@@ -53,4 +53,13 @@ typedef enum {uint64_t exynos4210_cmu_get_rate (Exynos4210CmuClock clock); +/* +* exynos4210 UART +*/ +DeviceState *exynos4210_uart_create (target_phys_addr_t addr, +int fifo_size, +int channel, +CharDriverState *chr, +qemu_irq irq); +#endif /* EXYNOS4210_H_ */
hw/exynos4210_uart.c new file +674 -0
674 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Re: [Qemu-devel] [PATCH v3 03/14] ARM: exynos4210: UART support
Quoted 7 lines · Evgeny Voevodin
From: Maksim Kozlov <[email protected]>
Add basic support of exynos4210 UART
Conflicts:
Makefile.target
Don't leave git's conflicts notes in the commit logs :-)
Quoted 47 lines
Signed-off-by Evgeny Voevodin <[email protected]>---
Makefile.target | 2 +- hw/exynos4210.c | 51 ++++ hw/exynos4210.h | 9 + hw/exynos4210_uart.c | 674 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 735 insertions(+), 1 deletions(-)create mode 100644
hw/exynos4210_uart.cMakefile.target +0
-0@@ -344,7 +344,7 @@ obj-arm-y = integratorcp.o versatilepb.o arm_pic.o arm_timer.oobj-arm-y += arm_boot.o pl011.o pl031.o pl050.o pl080.o pl110.o pl181.o pl190.o obj-arm-y += versatile_pci.o
obj-arm-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.oMakefile.target +1
-1-obj-arm-y += exynos4210.o exynos4210_cmu.o +obj-arm-y += exynos4210.o exynos4210_cmu.o exynos4210_uart.oobj-arm-y += armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o obj-arm-y += pl061.o
obj-arm-y += arm-semi.ohw/exynos4210.c +12
-0@@ -63,6 +63,18 @@ /* SFR Base Address for CMUs */ #define EXYNOS4210_CMU_BASE_ADDR 0x10030000 +/* UART's definitions */ +#define EXYNOS4210_UART_BASE_ADDR 0x13800000 +#define EXYNOS4210_UART_SHIFT 0x00010000 + +#define EXYNOS4210_UARTS_NUMBER 4 + +#define EXYNOS4210_UART_CHANNEL (addr) ((addr >> 16) & 0x7) +#define EXYNOS4210_UART0_FIFO_SIZE 256 +#define EXYNOS4210_UART1_FIFO_SIZE 64 +#define EXYNOS4210_UART2_FIFO_SIZE 16 +#define EXYNOS4210_UART3_FIFO_SIZE 16 + static struct arm_boot_info exynos4210_binfo = { .loader_start = EXYNOS4210_BASE_BOOT_ADDR,
hw/exynos4210.c static void exynos4210_init(ram_addr_t ram_size, · line 198
Quoted 8 lines
hw/exynos4210.c +5
-0@@ -179,6 +191,45 @@ static void exynos4210_init(ram_addr_t ram_size, /* CMU */ sysbus_create_simple("exynos4210.cmu", EXYNOS4210_CMU_BASE_ADDR, NULL); + /*** UARTs ***/ + for (n = 0; n < EXYNOS4210_UARTS_NUMBER; n++) { + + uint32_t addr = EXYNOS4210_UART_BASE_ADDR + EXYNOS4210_UART_SHIFT * n; + int channel = EXYNOS4210_UART_CHANNEL(addr);
Is there any case where channel is not the same as n ?
Quoted 641 lines
hw/exynos4210.c +34
-0+ qemu_irq uart_irq; + int fifo_size = 0; + + switch (channel) { + case 0: + fifo_size = EXYNOS4210_UART0_FIFO_SIZE; + break; + case 1: + fifo_size = EXYNOS4210_UART1_FIFO_SIZE; + break; + case 2: + fifo_size = EXYNOS4210_UART2_FIFO_SIZE; + break; + case 3: + fifo_size = EXYNOS4210_UART3_FIFO_SIZE; + break; + default: + fifo_size = 0; + PRINT_DEBUG("Wrong channel number: %d\n", channel); + break; + } + + if (fifo_size == 0) { + PRINT_DEBUG("Can't create UART%d with fifo size %d\n", + channel, fifo_size); + continue; + } + + uart_irq = NULL; + + exynos4210_uart_create(addr, fifo_size, channel, NULL, uart_irq); + } + + /*** Load kernel ***/ exynos4210_binfo.ram_size = ram_size;hw/exynos4210.h +9
-0@@ -53,4 +53,13 @@ typedef enum { uint64_t exynos4210_cmu_get_rate(Exynos4210CmuClock clock); +/* +* exynos4210 UART +*/ +DeviceState *exynos4210_uart_create (target_phys_addr_t addr, + int fifo_size, + int channel, + CharDriverState *chr, + qemu_irq irq); + #endif /* EXYNOS4210_H_ */hw/exynos4210_uart.c new file +580
-0@@ -0,0 +1,674 @@ +/* +* exynos4210 UART Emulation +* +* Copyright (C) 2011 Samsung Electronics Co Ltd. +* Maksim Kozlov, <[email protected]> +* +* Created on: 07.2011 +* +* +* 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, write to the Free Software Foundation, Inc., 51 +* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* +*/ + +#include "sysbus.h" +#include "sysemu.h" +#include "qemu-char.h" + +#include "exynos4210.h" + +#undef DEBUG_UART +#undef DEBUG_UART_EXTEND +#undef DEBUG_IRQ +#undef DEBUG_Rx_DATA +#undef DEBUG_Tx_DATA + + +//#define DEBUG_UART +//#define DEBUG_UART_EXTEND +//#define DEBUG_IRQ +//#define DEBUG_Rx_DATA +//#define DEBUG_Tx_DATA + + +#define PRINT_DEBUG(fmt, args...) \ + do {} while (0) +#define PRINT_DEBUG_EXTEND(fmt, args...) \ + do {} while (0) +#define PRINT_ERROR(fmt, args...) \ + do { \ + fprintf(stderr, " [%s:%d] "fmt, __func__, __LINE__, ##args); \ + } while (0) + +#ifdef DEBUG_UART + +#undef PRINT_DEBUG +#define PRINT_DEBUG(fmt, args...) \ + do { \ + fprintf(stderr, " [%s:%d] "fmt, __func__, __LINE__, ##args); \ + } while (0) + +#ifdef DEBUG_UART_EXTEND + +#undef PRINT_DEBUG_EXTEND +#define PRINT_DEBUG_EXTEND(fmt, args...) \ + do { \ + fprintf(stderr, " [%s:%d] "fmt, __func__, __LINE__, ##args); \ + } while (0) + +#endif /* EXTEND */ +#endif + + +/* +* Offsets for UART registers relative to SFR base address +* for UARTn +* +*/ +#define ULCON 0x0000/* Line Control */ +#define UCON 0x0004/* Control */ +#define UFCON 0x0008/* FIFO Control */ +#define UMCON 0x000C/* Modem Control */ +#define UTRSTAT 0x0010/* Tx/Rx Status */ +#define UERSTAT 0x0014/* Rx Error Status */ +#define UFSTAT 0x0018/* FIFO Status */ +#define UMSTAT 0x001C/* Modem Status */ +#define UTXH 0x0020/* Transmit Buffer */ +#define URXH 0x0024/* Receive Buffer */ +#define UBRDIV 0x0028/* Baud Rate Divisor */ +#define UFRACVAL 0x002C/* Divisor Fractional Value */ +#define UINTP 0x0030/* Interrupt Pending */ +#define UINTSP 0x0034/* Interrupt Source Pending */ +#define UINTM 0x0038/* Interrupt Mask */ + +/* +* for indexing register in the uint32_t array +* +* 'reg' - register offset (see offsets definitions above) +* +*/ +#define I_ (reg) (reg / sizeof(uint32_t)) + +typedef struct Exynos4210UartReg { + const char *name; /* the only reason is the debug output */ + target_phys_addr_t offset; + uint32_t reset_value; +}Exynos4210UartReg ; + +static Exynos4210UartReg exynos4210_uart_regs[] = { + {"ULCON" , ULCON , 0x00000000}, + {"UCON" , UCON , 0x00003000}, + {"UFCON" , UFCON , 0x00000000}, + {"UMCON" , UMCON , 0x00000000}, + {"UTRSTAT" , UTRSTAT , 0x00000006}, /* RO */ + {"UERSTAT" , UERSTAT , 0x00000000}, /* RO */ + {"UFSTAT" , UFSTAT , 0x00000000}, /* RO */ + {"UMSTAT" , UMSTAT , 0x00000000}, /* RO */ + {"UTXH" , UTXH , 0x5c5c5c5c}, /* WO, undefined reset value*/ + {"URXH" , URXH , 0x00000000}, /* RO */ + {"UBRDIV" , UBRDIV , 0x00000000}, + {"UFRACVAL", UFRACVAL, 0x00000000}, + {"UINTP" , UINTP , 0x00000000}, + {"UINTSP" , UINTSP , 0x00000000}, + {"UINTM" , UINTM , 0x00000000}, +}; + +#define EXYNOS4210_UART_REGS_MEM_SIZE 0x3c + +/* UART FIFO Control */ +#define UFCON_FIFO_ENABLE 0x1 +#define UFCON_Rx_FIFO_RESET 0x2 +#define UFCON_Tx_FIFO_RESET 0x4 +#define UFCON_Tx_FIFO_TRIGGER_LEVEL_SHIFT 8 +#define UFCON_Tx_FIFO_TRIGGER_LEVEL \ + (7 << UFCON_Tx_FIFO_TRIGGER_LEVEL_SHIFT) +#define UFCON_Rx_FIFO_TRIGGER_LEVEL_SHIFT 4 +#define UFCON_Rx_FIFO_TRIGGER_LEVEL \ + (7 << UFCON_Rx_FIFO_TRIGGER_LEVEL_SHIFT) + +/* Uart FIFO Status */ +#define UFSTAT_Rx_FIFO_COUNT 0xff +#define UFSTAT_Rx_FIFO_FULL 0x100 +#define UFSTAT_Rx_FIFO_ERROR 0x200 +#define UFSTAT_Tx_FIFO_COUNT_SHIFT 16 +#define UFSTAT_Tx_FIFO_COUNT (0xff << UFSTAT_Tx_FIFO_COUNT_SHIFT) +#define UFSTAT_Tx_FIFO_FULL_SHIFT 24 +#define UFSTAT_Tx_FIFO_FULL (1 << UFSTAT_Tx_FIFO_FULL_SHIFT) + +/* UART Interrupt Source Pending */ +#define UINTSP_RXD 0x1/* Receive interrupt */ +#define UINTSP_ERROR 0x2/* Error interrupt */ +#define UINTSP_TXD 0x4/* Transmit interrupt */ +#define UINTSP_MODEM 0x8/* Modem interrupt */ + +/* UART Line Control */ +#define ULCON_IR_MODE_SHIFT 6 +#define ULCON_PARITY_SHIFT 3 +#define ULCON_STOP_BIT_SHIFT 1 + + + +/* Specifies Tx/Rx Status */ +#define UTRSTAT_TRANSMITTER_EMPTY 0x4 +#define UTRSTAT_Tx_BUFFER_EMPTY 0x2 +#define UTRSTAT_Rx_BUFFER_DATA_READY 0x1 + +typedef struct { + uint8_t *data; + uint32_t sp, rp; /* store and retrieve pointers */ + uint32_t size; +}Exynos4210UartFIFO ; + +typedef struct { + SysBusDevice busdev; + MemoryRegion iomem; + + uint32_t reg[EXYNOS4210_UART_REGS_MEM_SIZE]; + Exynos4210UartFIFO rx; + Exynos4210UartFIFO tx; + + CharDriverState *chr; + qemu_irq irq; + + uint32_t channel; + +}Exynos4210UartState ; + + +#ifdef DEBUG_UART +/* The only meaning of life - debugging. This functions should be only used +* inside PRINT_DEBUG_... macroses +*/ +static const char *exynos4210_uart_regname(target_phys_addr_t offset) +{ + + int regs_number = sizeof(exynos4210_uart_regs)/sizeof(Exynos4210UartReg); + int i; + + for (i = 0; i < regs_number; i++) { + if (offset == exynos4210_uart_regs[i].offset) { + return exynos4210_uart_regs[i].name; + } + } + + return NULL; +} +#endif + + +static void fifo_store (Exynos4210UartFIFO *q,uint8_t ch) +{ + q->data[q->sp] = ch; + q->sp = (q->sp + 1) % q->size; +} + +static uint8_t fifo_retrieve (Exynos4210UartFIFO *q) +{ + uint8_t ret = q->data[q->rp]; + q->rp = (q->rp + 1) % q->size; + return ret; +} + +static int fifo_elements_number (Exynos4210UartFIFO *q) +{ + if (q->sp < q->rp) { + return q->size - q->rp + q->sp; + } + + return q->sp - q->rp; +} + +static int fifo_empty_elements_number (Exynos4210UartFIFO *q) +{ + return q->size - fifo_elements_number(q); +} + +static void fifo_reset (Exynos4210UartFIFO *q) +{ + if (q->data != NULL) { + g_free(q->data); + q->data = NULL; + } + + q->data = (uint8_t *)g_malloc0(q->size); + + q->sp = 0; + q->rp = 0; +} + +static uint32_t exynos4210_uart_Tx_FIFO_trigger_level (Exynos4210UartState *s) +{ + uint32_t level = 0; + uint32_t reg; + + reg = (s->reg[I_(UFCON)] && UFCON_Tx_FIFO_TRIGGER_LEVEL) >> + UFCON_Tx_FIFO_TRIGGER_LEVEL_SHIFT; + + switch (s->channel) { + case 0: + level = reg * 32; + break; + case 1: + case 4: + level = reg * 8; + break; + case 2: + case 3: + level = reg * 2; + break; + default: + level = 0; + PRINT_ERROR("Wrong UART chennel number: %d\n", s->channel); + } + + return level; +} + +static void exynos4210_uart_update_irq (Exynos4210UartState *s) +{ + /* + * The Tx interrupt is always requested if the number of data in the + * transmit FIFO is smaller than the trigger level. + */ + if (s->reg[I_(UFCON)] && UFCON_FIFO_ENABLE) { + + uint32_t count = (s->reg[I_(UFSTAT)] && UFSTAT_Tx_FIFO_COUNT) >> + UFSTAT_Tx_FIFO_COUNT_SHIFT; + + if (count <= exynos4210_uart_Tx_FIFO_trigger_level(s)) { + s->reg[I_(UINTSP)] |= UINTSP_TXD; + } + } + + s->reg[I_(UINTP)] = s->reg[I_(UINTSP)] & ~s->reg[I_(UINTM)]; + + if (s->reg[I_(UINTP)]) { + qemu_irq_raise(s->irq); + +#ifdef DEBUG_IRQ + fprintf(stderr, "UART%d: IRQ have been raised: %08x\n", + s->channel, s->reg[I_(UINTP)]); +#endif + + } else { + qemu_irq_lower(s->irq); + } +} + +static void exynos4210_uart_update_parameters (Exynos4210UartState *s) +{ + int speed, parity, data_bits, stop_bits, frame_size; + QEMUSerialSetParams ssp; + uint64_t uclk_rate; + + if (s->reg[I_(UBRDIV)] == 0) { + return; + } + + frame_size = 1; /* start bit */ + if (s->reg[I_(ULCON)] & 0x20) { + frame_size++; /* parity bit */ + if (s->reg[I_(ULCON)] & 0x28) { + parity = 'E'; + } else { + parity = 'O'; + } + } else { + parity = 'N'; + } + + if (s->reg[I_(ULCON)] & 0x4) { + stop_bits = 2; + } else { + stop_bits = 1; + } + + data_bits = (s->reg[I_(ULCON)] & 0x3) + 5; + + frame_size += data_bits + stop_bits; + + switch (s->channel) { + case 0: + uclk_rate = exynos4210_cmu_get_rate(SCLK_UART0); break; + case 1: + uclk_rate = exynos4210_cmu_get_rate(SCLK_UART1); break; + case 2: + uclk_rate = exynos4210_cmu_get_rate(SCLK_UART2); break; + case 3: + uclk_rate = exynos4210_cmu_get_rate(SCLK_UART3); break; + case 4: + uclk_rate = exynos4210_cmu_get_rate(SCLK_UART4); break; + default: + hw_error("%s: Incorrect UART channel: %d\n", + __func__, s->channel); + } + + speed = uclk_rate / ((16 * (s->reg[I_(UBRDIV)]) & 0xffff) + + (s->reg[I_(UFRACVAL)] & 0x7) + 16); + + ssp.speed = speed; + ssp.parity = parity; + ssp.data_bits = data_bits; + ssp.stop_bits = stop_bits; + + qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_SERIAL_SET_PARAMS, &ssp); + + PRINT_DEBUG("UART%d: speed: %d, parity: %c, data: %d, stop: %d\n", + s->channel, speed, parity, data_bits, stop_bits); +} + +static void exynos4210_uart_write (void *opaque,target_phys_addr_t offset, + uint64_t val, unsigned size) +{ + Exynos4210UartState *s = (Exynos4210UartState *)opaque; + uint8_t ch; + + if (offset > (EXYNOS4210_UART_REGS_MEM_SIZE - sizeof(uint32_t))) { + hw_error("exynos4210_cmu_write: Bad offset 0x%x\n", (int)offset); + } + + PRINT_DEBUG_EXTEND("UART%d: <0x%04x> %s <- 0x%08llx\n", + s->channel, offset, exynos4210_uart_regname(offset), val); + + switch (offset) { + case ULCON: + case UBRDIV: + case UFRACVAL: + s->reg[I_(offset)] = val; + exynos4210_uart_update_parameters(s); + break; + case UFCON: + s->reg[I_(UFCON)] = val; + if (val & UFCON_Rx_FIFO_RESET) { + fifo_reset(&s->rx); + s->reg[I_(UFCON)] &= ~UFCON_Rx_FIFO_RESET; + PRINT_DEBUG("UART%d: Rx FIFO Reset\n", s->channel); + } + if (val & UFCON_Tx_FIFO_RESET) { + fifo_reset(&s->tx); + s->reg[I_(UFCON)] &= ~UFCON_Tx_FIFO_RESET; + PRINT_DEBUG("UART%d: Tx FIFO Reset\n", s->channel); + } + break; + + case UTXH: + if (s->chr) { + s->reg[I_(UTRSTAT)] &= ~(UTRSTAT_TRANSMITTER_EMPTY | + UTRSTAT_Tx_BUFFER_EMPTY); + ch = (uint8_t)val; + qemu_chr_fe_write(s->chr, &ch, 1); +#ifdef DEBUG_Tx_DATA + fprintf(stderr, "%c", ch); +#endif + s->reg[I_(UTRSTAT)] |= UTRSTAT_TRANSMITTER_EMPTY | + UTRSTAT_Tx_BUFFER_EMPTY; + s->reg[I_(UINTSP)] |= UINTSP_TXD; + exynos4210_uart_update_irq(s); + } + break; + + case UINTP: + s->reg[I_(UINTP)] &= ~val; + /* XXX: It's the assumption that it works in this way */ + s->reg[I_(UINTSP)] &= ~val; + PRINT_DEBUG("UART%d: UINTP [%04x] have been cleared: %08x\n", + s->channel, offset, s->reg[I_(UINTP)]); + exynos4210_uart_update_irq(s); + break; + case UTRSTAT: + case UERSTAT: + case UFSTAT: + case UMSTAT: + case URXH: + PRINT_DEBUG("UART%d: Trying to write into RO register: %s [%04x]\n", + s->channel, exynos4210_uart_regname(offset), offset); + break; + case UINTSP: + /* XXX: It's the assumption that it works in this way */ + s->reg[I_(UINTSP)] &= ~val; + break; + case UINTM: + s->reg[I_(UINTM)] = val; + exynos4210_uart_update_irq(s); + break; + case UCON: + case UMCON: + default: + s->reg[I_(offset)] = val; + break; + } +} +static uint64_t exynos4210_uart_read (void *opaque,target_phys_addr_t offset, + unsigned size) +{ + Exynos4210UartState *s = (Exynos4210UartState *)opaque; + uint32_t res; + + if (offset > (EXYNOS4210_UART_REGS_MEM_SIZE - sizeof(uint32_t))) { + hw_error("exynos4210_cmu_read: Bad offset 0x%x\n", (int)offset); + } + + switch (offset) { + case UERSTAT: /* Read Only */ + res = s->reg[I_(UERSTAT)]; + s->reg[I_(UERSTAT)] = 0; + return res; + case UFSTAT: /* Read Only */ + s->reg[I_(UFSTAT)] = fifo_elements_number(&s->rx) & 0xff; + if (fifo_empty_elements_number(&s->rx) == 0) { + s->reg[I_(UFSTAT)] |= UFSTAT_Rx_FIFO_FULL; + s->reg[I_(UFSTAT)] &= ~0xff; + } + return s->reg[I_(UFSTAT)]; + case URXH: + if (s->reg[I_(UFCON)] & UFCON_FIFO_ENABLE) { + if (fifo_elements_number(&s->rx)) { + res = fifo_retrieve(&s->rx); +#ifdef DEBUG_Rx_DATA + fprintf(stderr, "%c", res); +#endif + if (!fifo_elements_number(&s->rx)) { + s->reg[I_(UTRSTAT)] &= ~UTRSTAT_Rx_BUFFER_DATA_READY; + } else { + s->reg[I_(UTRSTAT)] |= UTRSTAT_Rx_BUFFER_DATA_READY; + } + } else { + s->reg[I_(UINTSP)] |= UINTSP_ERROR; + exynos4210_uart_update_irq(s); + res = 0; + } + } else { + s->reg[I_(UTRSTAT)] &= ~UTRSTAT_Rx_BUFFER_DATA_READY; + res = s->reg[I_(URXH)]; + } + return res; + case UTXH: + PRINT_DEBUG("UART%d: Trying to read from WO register: %s [%04x]\n", + s->channel, exynos4210_uart_regname(offset), offset); + break; + default: + return s->reg[I_(offset)]; + break; + } + + return 0; +} + + +static const MemoryRegionOps exynos4210_uart_ops = { + .read = exynos4210_uart_read, + .write = exynos4210_uart_write, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + +static int exynos4210_uart_can_receive (void *opaque) +{ + Exynos4210UartState *s = (Exynos4210UartState *)opaque; + + return fifo_empty_elements_number(&s->rx); +} + + +static void exynos4210_uart_receive (void *opaque,const uint8_t *buf,int size) +{ + Exynos4210UartState *s = (Exynos4210UartState *)opaque; + int i; + + if (s->reg[I_(UFCON)] & UFCON_FIFO_ENABLE) { + if (fifo_empty_elements_number(&s->rx) < size) { + for (i = 0; i < fifo_empty_elements_number(&s->rx); i++) { + fifo_store(&s->rx, buf[i]); + } + s->reg[I_(UINTSP)] |= UINTSP_ERROR; + s->reg[I_(UTRSTAT)] |= UTRSTAT_Rx_BUFFER_DATA_READY; + } else { + for (i = 0; i < size; i++) { + fifo_store(&s->rx, buf[i]); + } + s->reg[I_(UTRSTAT)] |= UTRSTAT_Rx_BUFFER_DATA_READY; + } + /* XXX: after achieve trigger level*/ + s->reg[I_(UINTSP)] |= UINTSP_RXD; + } else { + s->reg[I_(URXH)] = buf[0]; + s->reg[I_(UINTSP)] |= UINTSP_RXD; + s->reg[I_(UTRSTAT)] |= UTRSTAT_Rx_BUFFER_DATA_READY; + } + + exynos4210_uart_update_irq(s); +} + + +static void exynos4210_uart_event (void *opaque,int event) +{ + /* +* TODO: Implement this. +* +*/ +} + + +static void exynos4210_uart_reset (DeviceState *dev) +{ + Exynos4210UartState *s = + container_of(dev, Exynos4210UartState, busdev.qdev); + int regs_number = sizeof(exynos4210_uart_regs)/sizeof(Exynos4210UartReg); + int i; + + for (i = 0; i < regs_number; i++) { + s->reg[I_(exynos4210_uart_regs[i].offset)] = + exynos4210_uart_regs[i].reset_value; + } + + fifo_reset(&s->rx); + fifo_reset(&s->tx); + + PRINT_DEBUG("UART%d: Rx FIFO size: %d\n", s->channel, s->rx.size); +} +
hw/exynos4210_uart.c line 590
Quoted 10 lines
hw/exynos4210_uart.c new file +10
-0+ +static const VMStateDescription vmstate_exynos4210_uart = { + .name = "exynos4210.uart", + .version_id = 1, + .minimum_version_id = 1, + .minimum_version_id_old = 1, + .fields = (VMStateField[]) { + /* + * TODO: We should save fifo too + */
Indeed.
Quoted 88 lines
hw/exynos4210_uart.c new file +84
-1+ VMSTATE_UINT32_ARRAY(reg, Exynos4210UartState, + EXYNOS4210_UART_REGS_MEM_SIZE), + VMSTATE_END_OF_LIST() + } +}; + +DeviceState *exynos4210_uart_create (target_phys_addr_t addr, + int fifo_size, + int channel, + CharDriverState *chr, + qemu_irq irq) +{ + DeviceState *dev; + SysBusDevice *bus; + + dev = qdev_create(NULL, "exynos4210.uart"); + + if (!chr) { + if (channel >= MAX_SERIAL_PORTS) { + hw_error("Only %d serial ports are supported by QEMU.\n", + MAX_SERIAL_PORTS); + } + chr = serial_hds[channel]; + if (!chr) { + chr = qemu_chr_new("exynos4210.uart", "null", NULL); + if (!(chr)) { + hw_error("Can't assign serial port to UART%d.\n", channel); + } + } + } + + qdev_prop_set_chr(dev, "chardev", chr); + qdev_prop_set_uint32(dev, "channel", channel); + qdev_prop_set_uint32(dev, "rx-size", fifo_size); + qdev_prop_set_uint32(dev, "tx-size", fifo_size); + + bus = sysbus_from_qdev(dev); + qdev_init_nofail(dev); + if (addr != (target_phys_addr_t)-1) { + sysbus_mmio_map(bus, 0, addr); + } + sysbus_connect_irq(bus, 0, irq); + + return dev; +} + +static int exynos4210_uart_init (SysBusDevice *dev) +{ + Exynos4210UartState *s = FROM_SYSBUS(Exynos4210UartState, dev); + + /* memory mapping */ + memory_region_init_io(&s->iomem, &exynos4210_uart_ops, s, "exynos4210.uart", + EXYNOS4210_UART_REGS_MEM_SIZE); + sysbus_init_mmio(dev, &s->iomem); + + sysbus_init_irq(dev, &s->irq); + + qemu_chr_add_handlers(s->chr, exynos4210_uart_can_receive, + exynos4210_uart_receive, exynos4210_uart_event, s); + + return 0; +} + +static SysBusDeviceInfo exynos4210_uart_info = { + .init = exynos4210_uart_init, + .qdev.name = "exynos4210.uart", + .qdev.size = sizeof(Exynos4210UartState), + .qdev.vmsd = &vmstate_exynos4210_uart, + .qdev.reset = exynos4210_uart_reset, + .qdev.props = (Property[]) { + DEFINE_PROP_CHR("chardev", Exynos4210UartState, chr), + DEFINE_PROP_UINT32("channel", Exynos4210UartState, channel, 0), + DEFINE_PROP_UINT32("rx-size", Exynos4210UartState, rx.size, 16), + DEFINE_PROP_UINT32("tx-size", Exynos4210UartState, tx.size, 16), + DEFINE_PROP_END_OF_LIST(), + } +}; + +static void exynos4210_uart_register (void ) +{ + sysbus_register_withprop(&exynos4210_uart_info); +} + +device_init (exynos4210_uart_register) --1.7.4.1
PATCH v3 4/14 hw/sysbus.h: Increase maximum number of device IRQs.
In reply to Evgeny VoevodinSamsung exynos4210 Interrupt Combiner needs 512 IRQ sources.
--- hw/sysbus.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
hw/sysbus.h +1 -1
@@ -8,7 +8,7 @@#define QDEV_MAX_MMIO 32#define QDEV_MAX_PIO 32 -#define QDEV_MAX_IRQ 256 +#define QDEV_MAX_IRQ 512typedef struct SysBusDevice SysBusDevice ;typedef void (*mmio_mapfunc )(SysBusDevice *dev,target_phys_addr_t addr);
Signature · 1 line
1.7.4.1
PATCH v3 5/14 ARM: exynos4210: IRQ subsystem support.
In reply to Evgeny Voevodin--- Makefile.target | 3 +- hw/exynos4210.c | 175 ++++++++++++++++- hw/exynos4210.h | 42 ++++ hw/exynos4210_combiner.c | 385 ++++++++++++++++++++++++++++++++++ hw/exynos4210_gic.c | 510 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 1113 insertions(+), 2 deletions(-) create mode 100644 hw/exynos4210_combiner.c create mode 100644 hw/exynos4210_gic.c
Makefile.target +2 -1
@@ -344,7 +344,8 @@ obj-arm-y = integratorcp.o versatilepb.o arm_pic.o arm_timer.o obj-arm-y += arm_boot.o pl011.o pl031.o pl050.o pl080.o pl110.o pl181.o pl190.o obj-arm-y += versatile_pci.o obj-arm-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.o -obj-arm-y += exynos4210.o exynos4210_cmu.o exynos4210_uart.o +obj-arm-y += exynos4210.o exynos4210_cmu.o exynos4210_uart.o exynos4210_gic.o \ + exynos4210_combiner.o obj-arm-y += armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o obj-arm-y += pl061.o obj-arm-y += arm-semi.o
hw/exynos4210.c +174 -1
220 lines not on this page · raw message
hw/exynos4210.h +42 -0
48 lines not on this page · raw message
hw/exynos4210_combiner.c new file +385 -0
385 lines not on this page · raw message
hw/exynos4210_gic.c new file +510 -0
510 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH v3 6/14 ARM: exynos4210: PWM support.
In reply to Evgeny Voevodin--- Makefile.target | 2 +- hw/exynos4210.c | 12 ++ hw/exynos4210_pwm.c | 433 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 446 insertions(+), 1 deletions(-) create mode 100644 hw/exynos4210_pwm.c
Makefile.target +1 -1
@@ -345,7 +345,7 @@ obj-arm-y += arm_boot.o pl011.o pl031.o pl050.o pl080.o pl110.o pl181.o pl190.o obj-arm-y += versatile_pci.o obj-arm-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.o obj-arm-y += exynos4210.o exynos4210_cmu.o exynos4210_uart.o exynos4210_gic.o \ - exynos4210_combiner.o + exynos4210_combiner.o exynos4210_pwm.o obj-arm-y += armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o obj-arm-y += pl061.o obj-arm-y += arm-semi.o
hw/exynos4210.c +12 -0
@@ -65,6 +65,9 @@/* SFR Base Address for CMUs */ #define EXYNOS4210_CMU_BASE_ADDR 0x10030000 +/* PWM */ +#define EXYNOS4210_PWM_BASE_ADDR 0x139D0000 +/* UART's definitions */ #define EXYNOS4210_UART_BASE_ADDR 0x13800000#define EXYNOS4210_UART_SHIFT 0x00010000
@@ -364,6 +367,15 @@ static void exynos4210_init(ram_addr_t ram_size,/* CMU */ sysbus_create_simple ("exynos4210.cmu" ,EXYNOS4210_CMU_BASE_ADDR ,NULL ); +/* PWM */ +sysbus_create_varargs ("exynos4210.pwm" ,EXYNOS4210_PWM_BASE_ADDR , + irq_table[exynos4210_get_irq (22 ,0 )], + irq_table[exynos4210_get_irq (22 ,1 )], + irq_table[exynos4210_get_irq (22 ,2 )], + irq_table[exynos4210_get_irq (22 ,3 )], + irq_table[exynos4210_get_irq (22 ,4 )], +NULL ); +/*** UARTs ***/ for (n =0 ; n <EXYNOS4210_UARTS_NUMBER ; n++) {
hw/exynos4210_pwm.c new file +433 -0
433 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Re: [Qemu-devel] [PATCH v3 06/14] ARM: exynos4210: PWM support.
Quoted 272 lines · Evgeny Voevodin
Signed-off-by Evgeny Voevodin <[email protected]>---
Makefile.target | 2 +-
hw/exynos4210.c | 12 ++
hw/exynos4210_pwm.c | 433 +++++++++++++++++++++++++++++++++++++++++++++++++++3 files changed, 446 insertions(+), 1 deletions(-)create mode 100644
hw/exynos4210_pwm.cMakefile.target +0
-0@@ -345,7 +345,7 @@ obj-arm-y += arm_boot.o pl011.o pl031.o pl050.o pl080.o pl110.o pl181.o pl190.oobj-arm-y += versatile_pci.o
obj-arm-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.o obj-arm-y += exynos4210.o exynos4210_cmu.o exynos4210_uart.o exynos4210_gic.o \
- exynos4210_combiner.o
+ exynos4210_combiner.o exynos4210_pwm.o
obj-arm-y += armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o obj-arm-y += pl061.o
obj-arm-y += arm-semi.ohw/exynos4210.c +12
-0@@ -65,6 +65,9 @@ /* SFR Base Address for CMUs */ #define EXYNOS4210_CMU_BASE_ADDR 0x10030000 +/* PWM */ +#define EXYNOS4210_PWM_BASE_ADDR 0x139D0000 + /* UART's definitions */ #define EXYNOS4210_UART_BASE_ADDR 0x13800000 #define EXYNOS4210_UART_SHIFT 0x00010000@@ -364,6 +367,15 @@ static void exynos4210_init(ram_addr_t ram_size, /* CMU */ sysbus_create_simple("exynos4210.cmu", EXYNOS4210_CMU_BASE_ADDR, NULL); + /* PWM */ + sysbus_create_varargs("exynos4210.pwm", EXYNOS4210_PWM_BASE_ADDR, + irq_table[exynos4210_get_irq(22, 0)], + irq_table[exynos4210_get_irq(22, 1)], + irq_table[exynos4210_get_irq(22, 2)], + irq_table[exynos4210_get_irq(22, 3)], + irq_table[exynos4210_get_irq(22, 4)], + NULL); + /*** UARTs ***/ for (n = 0; n < EXYNOS4210_UARTS_NUMBER; n++) {hw/exynos4210_pwm.c new file +214
-0@@ -0,0 +1,433 @@ +/* +* Samsung exynos4210 Pulse Width Modulation Timer +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. +* All rights reserved. +* +* Evgeny Voevodin <[email protected]> +* +* 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, write to the Free Software Foundation, Inc., 51 +* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "sysbus.h" +#include "qemu-timer.h" +#include "qemu-common.h" +#include "hw.h" + +#include "exynos4210.h" + +//#define DEBUG_PWM + +#ifdef DEBUG_PWM +#define DPRINTF (fmt, ...) \ + do { fprintf(stdout, "PWM: [%24s:%5d] " fmt, __func__, __LINE__, \ + ## __VA_ARGS__); } while (0) +#else +#define DPRINTF (fmt, ...) do {} while (0) +#endif + +#define EXYNOS4210_PWM_TIMERS_NUM 5 +#define EXYNOS4210_PWM_REG_MEM_SIZE 0x50 + +#define TCFG0 0x0000 +#define TCFG1 0x0004 +#define TCON 0x0008 +#define TCNTB0 0x000C +#define TCMPB0 0x0010 +#define TCNTO0 0x0014 +#define TCNTB1 0x0018 +#define TCMPB1 0x001C +#define TCNTO1 0x0020 +#define TCNTB2 0x0024 +#define TCMPB2 0x0028 +#define TCNTO2 0x002C +#define TCNTB3 0x0030 +#define TCMPB3 0x0034 +#define TCNTO3 0x0038 +#define TCNTB4 0x003C +#define TCNTO4 0x0040 +#define TINT_CSTAT 0x0044 + +#define TCNTB(x) (0xC*x) +#define TCMPB(x) (0xC*x+1) +#define TCNTO(x) (0xC*x+2) + +#define GET_PRESCALER(reg, x) ((reg&(0xFF<<(8*x)))>>8*x) +#define GET_DIVIDER(reg, x) (1<<((0xF<<(4*x))>>(4*x))) + +/* +* Attention! Timer4 doesn't have OUTPUT_INVERTER, +* so Auto Reload bit is not accessible by macros! +*/ +#define TCON_TIMER_BASE(x) ((x ? 1 : 0)*4 + 4*x) +#define TCON_TIMER_START(x) (1<<(TCON_TIMER_BASE(x) + 0)) +#define TCON_TIMER_MANUAL_UPD(x) (1<<(TCON_TIMER_BASE(x) + 1)) +#define TCON_TIMER_OUTPUT_INV(x) (1<<(TCON_TIMER_BASE(x) + 2)) +#define TCON_TIMER_AUTO_RELOAD(x) (1<<(TCON_TIMER_BASE(x) + 3)) +#define TCON_TIMER4_AUTO_RELOAD (1<<22) + +#define TINT_CSTAT_STATUS(x) (1<<(5+x)) +#define TINT_CSTAT_ENABLE(x) (1<<x) + +/* timer struct */ +typedef struct { + uint32_t id; /* timer id */ + qemu_irq irq; /* local timer irq */ + uint32_t freq; /* timer frequency */ + + /* use ptimer.c to represent count down timer */ + ptimer_state *ptimer; /* timer */ + + /* registers */ + uint32_t reg_tcntb; /* counter register buffer */ + uint32_t reg_tcmpb; /* compare register buffer */ + +}Exynos4210_pwm ; + + +typedef struct Exynos4210PWMState { + SysBusDevice busdev; + MemoryRegion iomem; + + uint32_t reg_tcfg[2]; + uint32_t reg_tcon; + uint32_t reg_tint_cstat; + + Exynos4210CmuClock clk; /* clock source for timer */ + Exynos4210_pwm timer[EXYNOS4210_PWM_TIMERS_NUM]; + +}Exynos4210PWMState ; + +/*** VMState ***/ +static const VMStateDescription VMState_Exynos4210_pwm = { + .name = "exynos4210.pwm.pwm", + .version_id = 1, + .minimum_version_id = 1, + .minimum_version_id_old = 1, + .fields = (VMStateField[]) { + VMSTATE_UINT32(id, Exynos4210_pwm), + VMSTATE_UINT32(freq, Exynos4210_pwm), + VMSTATE_UINT32(reg_tcntb, Exynos4210_pwm), + VMSTATE_UINT32(reg_tcmpb, Exynos4210_pwm), + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription VMState_Exynos4210PWMState = { + .name = "exynos4210.pwm", + .version_id = 1, + .minimum_version_id = 1, + .minimum_version_id_old = 1, + .fields = (VMStateField[]) { + VMSTATE_UINT32_ARRAY(reg_tcfg, Exynos4210PWMState, 2), + VMSTATE_UINT32(reg_tcon, Exynos4210PWMState), + VMSTATE_UINT32(reg_tint_cstat, Exynos4210PWMState), + VMSTATE_STRUCT_ARRAY(timer, Exynos4210PWMState, + EXYNOS4210_PWM_TIMERS_NUM, 0, + VMState_Exynos4210_pwm, Exynos4210_pwm), + VMSTATE_END_OF_LIST() + } +}; + +/* +* PWM update frequency +*/ +static void exynos4210_pwm_update_freq (Exynos4210PWMState *s,uint32_t id) +{ + uint32_t freq; + freq = s->timer[id].freq; + if (id > 1) { + s->timer[id].freq = exynos4210_cmu_get_rate(s->clk) / + ((GET_PRESCALER(s->reg_tcfg[0], 1) + 1) * + (1<<GET_DIVIDER(s->reg_tcfg[1], id))); + } else { + s->timer[id].freq = exynos4210_cmu_get_rate(s->clk) / + ((GET_PRESCALER(s->reg_tcfg[0], 0) + 1) * + (1<<GET_DIVIDER(s->preg_tcfg[1], id))); + } + + if (freq != s->timer[id].freq) { + ptimer_set_freq(s->timer[id].ptimer, s->timer[id].freq); + DPRINTF("freq=%dHz\n", s->timer[id].freq); + } +} + +/* +* Counter tick handler +*/ +static void exynos4210_pwm_tick (void *opaque,uint32_t id) +{ + Exynos4210PWMState *s = (Exynos4210PWMState *)opaque; + bool cmp; + + DPRINTF("timer %d tick\n", id); + + /* set irq status */ + s->reg_tint_cstat |= TINT_CSTAT_STATUS(id); + + /* raise IRQ */ + if (s->reg_tint_cstat & TINT_CSTAT_ENABLE(id)) { + DPRINTF("timer %d IRQ\n", id); + qemu_irq_raise(s->timer[id].irq); + } + + /* reload timer */ + if (id != 4) { + cmp = s->reg_tcon & TCON_TIMER_AUTO_RELOAD(id); + } else { + cmp = s->reg_tcon & TCON_TIMER4_AUTO_RELOAD; + } + + if (cmp) { + DPRINTF("auto reload timer %d count to %x\n", id, + s->timer[id].reg_tcntb); + ptimer_set_count(s->timer[id].ptimer, s->timer[id].reg_tcntb); + ptimer_run(s->timer[id].ptimer, 1); + } else { + /* stop timer, set status to STOP, see Basic Timer Operation */ + s->reg_tcon = ~TCON_TIMER_START(id); + ptimer_stop(s->timer[id].ptimer); + } +} + +static void exynos4210_pwm_tick0 (void *opaque) +{ + exynos4210_pwm_tick(opaque, 0); +} +static void exynos4210_pwm_tick1 (void *opaque) +{ + exynos4210_pwm_tick(opaque, 1); +} +static void exynos4210_pwm_tick2 (void *opaque) +{
hw/exynos4210_pwm.c line 224
Quoted 10 lines
hw/exynos4210_pwm.c new file +10
-0+ exynos4210_pwm_tick(opaque, 2); +} +static void exynos4210_pwm_tick3 (void *opaque) +{ + exynos4210_pwm_tick(opaque, 3); +} +static void exynos4210_pwm_tick4 (void *opaque) +{ + exynos4210_pwm_tick(opaque, 4); +}
If you make the Exynos4210_pwm struct include a pointer back to the Exynos4210PWMState struct, then you can make exynos4210_pwm_tick take a pointer to the Exynos4210_pwm struct, and then you can drop these wrapper functions and just say
bh[i] = qemu_bh_new(exynos4210_pwm_tick, &s->timer[i]);
Quoted 189 lines
hw/exynos4210_pwm.c new file +189
-0+ +/* +* PWM Read +*/ +static uint64_t exynos4210_pwm_read (void *opaque,target_phys_addr_t offset, + unsigned size) +{ + Exynos4210PWMState *s = (Exynos4210PWMState *)opaque; + uint32_t value = 0; + int index; + + switch (offset) { + case TCFG0: case TCFG1: + index = (offset - TCFG0)>>2; + value = s->reg_tcfg[index]; + break; + + case TCON: + value = s->reg_tcon; + break; + + case TCNTB0: case TCNTB1: + case TCNTB2: case TCNTB3: case TCNTB4: + index = (offset - TCNTB0)/0xC; + value = s->timer[index].reg_tcntb; + break; + + case TCMPB0: case TCMPB1: + case TCMPB2: case TCMPB3: + index = (offset - TCMPB0)/0xC; + value = s->timer[index].reg_tcmpb; + break; + + case TCNTO0: case TCNTO1: + case TCNTO2: case TCNTO3: case TCNTO4: + index = (offset == TCNTO4) ? 4 : (offset - TCNTO0)/0xC; + value = ptimer_get_count(s->timer[index].ptimer); + break; + + case TINT_CSTAT: + value = s->reg_tint_cstat; + break; + + default: + fprintf(stderr, + "[exynos4210.pwm: bad read offset " TARGET_FMT_plx "]\n", + offset); + break; + } + return value; +} + +/* +* PWM Write +*/ +static void exynos4210_pwm_write (void *opaque,target_phys_addr_t offset, + uint64_t value, unsigned size) +{ + Exynos4210PWMState *s = (Exynos4210PWMState *)opaque; + int index; + uint32_t new_val; + int i; + + switch (offset) { + case TCFG0: case TCFG1: + index = (offset - TCFG0)>>2; + s->reg_tcfg[index] = value; + + /* update timers frequencies */ + for (i = 0; i < EXYNOS4210_PWM_TIMERS_NUM; i++) { + exynos4210_pwm_update_freq(s, s->timer[i].id); + } + break; + + case TCON: + for (i = 0; i < EXYNOS4210_PWM_TIMERS_NUM; i++) { + if ((value & TCON_TIMER_MANUAL_UPD(i)) > + (s->reg_tcon & TCON_TIMER_MANUAL_UPD(i))) { + /* + * TCNTB and TCMPB are loaded into TCNT and TCMP. + * Update timers. + */ + + /* this will start timer to run, this ok, because + * during processing start bit timer will be stopped + * if needed */ + ptimer_set_count(s->timer[i].ptimer, s->timer[i].reg_tcntb); + DPRINTF("set timer %d count to %x\n", i, + s->timer[i].reg_tcntb); + } + + if ((value & TCON_TIMER_START(i)) > + (s->reg_tcon & TCON_TIMER_START(i))) { + /* changed to start */ + ptimer_run(s->timer[i].ptimer, 1); + DPRINTF("run timer %d\n", i); + } + + if ((value & TCON_TIMER_START(i)) < + (s->reg_tcon & TCON_TIMER_START(i))) { + /* changed to stop */ + ptimer_stop(s->timer[i].ptimer); + DPRINTF("stop timer %d\n", i); + } + } + s->reg_tcon = value; + break; + + case TCNTB0: case TCNTB1: + case TCNTB2: case TCNTB3: case TCNTB4: + index = (offset - TCNTB0)/0xC; + s->timer[index].reg_tcntb = value; + break; + + case TCMPB0: case TCMPB1: + case TCMPB2: case TCMPB3: + index = (offset - TCMPB0)/0xC; + s->timer[index].reg_tcmpb = value; + break; + + case TINT_CSTAT: + new_val = (s->reg_tint_cstat&0x3E0) + (0x1F & value); + new_val &= ~(0x3E0 & value); + + for (i = 0; i < EXYNOS4210_PWM_TIMERS_NUM; i++) { + if ((new_val & TINT_CSTAT_STATUS(i)) < + (s->reg_tint_cstat & TINT_CSTAT_STATUS(i))) { + qemu_irq_lower(s->timer[i].irq); + } + } + + s->reg_tint_cstat = new_val; + break; + + default: + fprintf(stderr, + "[exynos4210.pwm: bad write offset " TARGET_FMT_plx "]\n", + offset); + break; + + } +} + +/* +* Set default values to timer fields and registers +*/ +static void exynos4210_pwm_reset (Exynos4210PWMState *s) +{ + int i; + s->reg_tcfg[0] = 0x0101; + s->reg_tcfg[1] = 0x0; + s->reg_tcon = 0; + s->reg_tint_cstat = 0; + for (i = 0; i < EXYNOS4210_PWM_TIMERS_NUM; i++) { + s->timer[i].reg_tcmpb = 0; + s->timer[i].reg_tcntb = 0; + + exynos4210_pwm_update_freq(s, s->timer[i].id); + ptimer_stop(s->timer[i].ptimer); + } +} + +static const MemoryRegionOps exynos4210_pwm_ops = { + .read = exynos4210_pwm_read, + .write = exynos4210_pwm_write, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + +/* +* PWM timer initialization +*/ +static int exynos4210_pwm_init (SysBusDevice *dev) +{ + Exynos4210PWMState *s = FROM_SYSBUS(Exynos4210PWMState, dev); + int i; + QEMUBH * bh[EXYNOS4210_PWM_TIMERS_NUM]; + + s->clk = ACLK_100; + + bh[0] = qemu_bh_new(exynos4210_pwm_tick0, s); + bh[1] = qemu_bh_new(exynos4210_pwm_tick1, s); + bh[2] = qemu_bh_new(exynos4210_pwm_tick2, s); + bh[3] = qemu_bh_new(exynos4210_pwm_tick3, s); + bh[4] = qemu_bh_new(exynos4210_pwm_tick4, s); + + for (i = 0; i < EXYNOS4210_PWM_TIMERS_NUM; i++) { + sysbus_init_irq(dev, &s->timer[i].irq); + s->timer[i].ptimer = ptimer_init(bh[i]); + s->timer[i].id = i;
hw/exynos4210_pwm.c line 423
Quoted 10 lines
hw/exynos4210_pwm.c new file +10
-0+ } + + memory_region_init_io(&s->iomem, &exynos4210_pwm_ops, s, "exynos4210-pwm", + EXYNOS4210_PWM_REG_MEM_SIZE); + sysbus_init_mmio(dev, &s->iomem); + + exynos4210_pwm_reset(s); + + qemu_register_reset((QEMUResetHandler *)exynos4210_pwm_reset, s); + vmstate_register(NULL, -1, &VMState_Exynos4210PWMState, s);
Same remarks about reset, vmstate as in other patch review mail.
Quoted 14 lines
hw/exynos4210_pwm.c new file +10
-1+ return 0; +} + +static void exynos4210_pwm_register_devices (void ) +{ + sysbus_register_dev("exynos4210.pwm", sizeof(Exynos4210PWMState), + exynos4210_pwm_init); +} + +device_init (exynos4210_pwm_register_devices) --1.7.4.1
PATCH v3 7/14 hw/arm_boot.c: Add new secondary CPU bootloader.
In reply to Evgeny VoevodinSecondary CPU bootloader enables interrupt and issues wfi until start address is written to system controller. The position where to find this start address is hardcoded to 0x10000030. This commit adds new bootloader for secondary CPU which allows a target board to cpecify a position where to find start address. If target board doesn't specify start address then default 0x10000030 is used
--- hw/arm-misc.h | 1 + hw/arm_boot.c | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-)
hw/arm-misc.h +1 -0
@@ -31,6 +31,7 @@ struct arm_boot_info {const char *initrd_filename;target_phys_addr_t loader_start;target_phys_addr_t smp_loader_start; +target_phys_addr_t smp_bootreg_addr;target_phys_addr_t smp_priv_base;int nb_cpus;int board_id;
hw/arm_boot.c +15 -7
@@ -31,17 +31,17 @@ static uint32_t bootloader[] = {/* Entry point for secondary CPUs. Enable interrupt controller and Issue WFI until start address is written to system controller. */ static uint32_t smpboot[] = { -0xe59f0020 ,/* ldr r0, privbase */ -0xe3a01001 ,/* mov r1, #1 */ -0xe5801100 ,/* str r1, [r0, #0x100] */ -0xe3a00201 ,/* mov r0, #0x10000000 */ -0xe3800030 ,/* orr r0, #0x30 */ +0xe59f201c ,/* ldr r2, privbase */ +0xe59f001c ,/* ldr r0, startaddr */ +0xe3a01001 ,/* mov r1, #1 */ +0xe5821100 ,/* str r1, [r2, #256] */ 0xe320f003 ,/* wfi */ 0xe5901000 ,/* ldr r1, [r0] */ 0xe1110001 ,/* tst r1, r1 */ 0x0afffffb ,/* beq <wfi> */ 0xe12fff11 ,/* bx r1 */ -0 /* privbase: Private memory region base address. */ +0 ,/* privbase: Private memory region base address. */ +0 /* bootreg: Boot register address is hold here */ };#define WRITE_WORD (p, value) do { \
@@ -179,6 +179,7 @@ static void do_cpu_reset(void *opaque) {CPUState *env = opaque;const struct arm_boot_info *info = env->boot_info; +uint8_t smp_bootreg_addr[4 ] = {0 };cpu_reset (env);if (info) {
@@ -197,6 +198,8 @@ static void do_cpu_reset(void *opaque) info->loader_start); } }else { +cpu_physical_memory_rw (info->smp_bootreg_addr, smp_bootreg_addr, +sizeof (smp_bootreg_addr),1 ); env->regs[15 ] = info->smp_loader_start; } }
@@ -262,6 +265,7 @@ void arm_load_kernel(CPUState *env, struct arm_boot_info *info) }else { initrd_size =0 ; } + bootloader[1 ] |= info->board_id &0xff ; bootloader[2 ] |= (info->board_id >>8 ) &0xff ; bootloader[5 ] = info->loader_start +KERNEL_ARGS_ADDR ;
@@ -272,7 +276,11 @@ void arm_load_kernel(CPUState *env, struct arm_boot_info *info)rom_add_blob_fixed ("bootloader" , bootloader,sizeof (bootloader), info->loader_start);if (info->nb_cpus >1 ) { - smpboot[10 ] = info->smp_priv_base; +if (!info->smp_bootreg_addr) { + info->smp_bootreg_addr =0x10000030 ; + } + smpboot[(sizeof (smpboot) -8 )/4 ] = info->smp_priv_base; + smpboot[(sizeof (smpboot) -4 )/4 ] = info->smp_bootreg_addr;for (n =0 ; n <sizeof (smpboot) /4 ; n++) { smpboot[n] =tswap32 (smpboot[n]); }
Signature · 1 line
1.7.4.1
Re: [Qemu-devel] [PATCH v3 07/14] hw/arm_boot.c: Add new secondary CPU bootloader.
Quoted 6 lines · Evgeny Voevodin
Secondary CPU bootloader enables interrupt and issues wfi until start address is written to system controller. The position where to find this start address is hardcoded to
0x10000030. This commit adds new bootloader for secondary CPU which allows a target board to cpecify a position where to find start address. If target board doesn't specify start address then default0x10000030is used
This commit message isn't quite right. We aren't adding a new bootloader, we're modifying the existing one.
Quoted 36 lines
Signed-off-by Evgeny Voevodin <[email protected]>---
hw/arm-misc.h | 1 +
hw/arm_boot.c | 22 +++++++++++++++-------2 files changed, 16 insertions(+), 7 deletions(-)hw/arm-misc.h +1
-0@@ -31,6 +31,7 @@ struct arm_boot_info { const char *initrd_filename; target_phys_addr_t loader_start; target_phys_addr_t smp_loader_start; + target_phys_addr_t smp_bootreg_addr; target_phys_addr_t smp_priv_base; int nb_cpus; int board_id;hw/arm_boot.c +0
-0@@ -31,17 +31,17 @@ static uint32_t bootloader[] = { /* Entry point for secondary CPUs. Enable interrupt controller andIssue WFI until start address is written to system controller. */ static
uint32_tsmpboot[] = {
- 0xe59f0020, /* ldr r0, privbase */
- 0xe3a01001, /* mov r1, #1 */
- 0xe5801100, /* str r1, [r0, #0x100] */
- 0xe3a00201, /* mov r0, #0x10000000 */
- 0xe3800030, /* orr r0, #0x30 */
+ 0xe59f201c, /* ldr r2, privbase */
+ 0xe59f001c, /* ldr r0, startaddr */
+ 0xe3a01001, /* mov r1, #1 */
+ 0xe5821100, /* str r1, [r2, #256] */
Quoted 8 lines
0xe320f003, /* wfi */
0xe5901000, /* ldr r1, [r0] */
0xe1110001, /* tst r1, r1 */
0x0afffffb, /* beq <wfi> */
0xe12fff11, /* bx r1 */
- 0 /* privbase: Private memory region base address. */
+ 0, /* privbase: Private memory region base address. */
+ 0 /* bootreg: Boot register address is hold here */
"held"
Quoted 12 lines
};
#define
WRITE_WORD(p, value)do { \hw/arm_boot.c +1
-0@@ -179,6 +179,7 @@ static void do_cpu_reset(void *opaque) { CPUState *env = opaque; const struct arm_boot_info *info = env->boot_info; + uint8_t smp_bootreg_addr[4] = {0}; cpu_reset(env); if (info) {
hw/arm_boot.c static void do_cpu_reset(void *opaque) · line 202
Quoted 5 lines
hw/arm_boot.c +2
-0@@ -197,6 +198,8 @@ static void do_cpu_reset(void *opaque) info->loader_start); } } else { + cpu_physical_memory_rw(info->smp_bootreg_addr, smp_bootreg_addr, + sizeof(smp_bootreg_addr), 1);
Any reason not to use WRITE_WORD() ?
hw/arm_boot.c void arm_load_kernel(CPUState *env, struct arm_boot_info *info) · line 271
Quoted 11 lines
hw/arm_boot.c +1
-0env->regs[15] = info->smp_loader_start; } }@@ -262,6 +265,7 @@ void arm_load_kernel(CPUState *env, struct arm_boot_info *info) } else { initrd_size = 0; } + bootloader[1] |= info->board_id & 0xff; bootloader[2] |= (info->board_id >> 8) & 0xff; bootloader[5] = info->loader_start + KERNEL_ARGS_ADDR;
Stray whitespace change, please remove from patch.
hw/arm_boot.c void arm_load_kernel(CPUState *env, struct arm_boot_info *info) · line 283
Quoted 10 lines
hw/arm_boot.c +5
-1@@ -272,7 +276,11 @@ void arm_load_kernel(CPUState *env, struct arm_boot_info *info) rom_add_blob_fixed("bootloader", bootloader, sizeof(bootloader), info->loader_start); if (info->nb_cpus > 1) { - smpboot[10] = info->smp_priv_base; + if (!info->smp_bootreg_addr) { + info->smp_bootreg_addr = 0x10000030; + } + smpboot[(sizeof(smpboot) - 8)/4] = info->smp_priv_base; + smpboot[(sizeof(smpboot) - 4)/4] = info->smp_bootreg_addr;
smpboot[ARRAY_SIZE(smpboot) - 1] = ...
Quoted 5 lines
hw/arm_boot.c +0
-1for (n = 0; n < sizeof(smpboot) / 4; n++) { smpboot[n] = tswap32(smpboot[n]); } --1.7.4.1
-- PMM
PATCH v3 8/14 ARM: exynos4210: MCT support.
In reply to Evgeny Voevodin--- Makefile.target | 2 +- hw/exynos4210.c | 19 + hw/exynos4210_mct.c | 1486 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1506 insertions(+), 1 deletions(-) create mode 100644 hw/exynos4210_mct.c
Makefile.target +1 -1
@@ -345,7 +345,7 @@ obj-arm-y += arm_boot.o pl011.o pl031.o pl050.o pl080.o pl110.o pl181.o pl190.o obj-arm-y += versatile_pci.o obj-arm-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.o obj-arm-y += exynos4210.o exynos4210_cmu.o exynos4210_uart.o exynos4210_gic.o \ - exynos4210_combiner.o exynos4210_pwm.o + exynos4210_combiner.o exynos4210_pwm.o exynos4210_mct.o obj-arm-y += armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o obj-arm-y += pl061.o obj-arm-y += arm-semi.o
hw/exynos4210.c +19 -0
@@ -68,6 +68,9 @@/* PWM */ #define EXYNOS4210_PWM_BASE_ADDR 0x139D0000 +/* MCT */ +#define EXYNOS4210_MCT_BASE_ADDR 0x10050000 +/* UART's definitions */ #define EXYNOS4210_UART_BASE_ADDR 0x13800000#define EXYNOS4210_UART_SHIFT 0x00010000
@@ -376,6 +379,22 @@ static void exynos4210_init(ram_addr_t ram_size, irq_table[exynos4210_get_irq (22 ,4 )], NULL); +/* Multi Core Timer */ + dev =qdev_create (NULL ,"exynos4210.mct" ); +qdev_init_nofail (dev); + busdev =sysbus_from_qdev (dev); +for (n =0 ; n <4 ; n++) { +/* Connect global timer interrupts to Combiner gpio_in */ +sysbus_connect_irq (busdev, n, + irq_table[exynos4210_get_irq (1 ,4 + n)]); + } +/* Connect local timer interrupts to Combiner gpio_in */ +sysbus_connect_irq (busdev,4 , + irq_table[exynos4210_get_irq (51 ,0 )]); +sysbus_connect_irq (busdev,5 , + irq_table[exynos4210_get_irq (35 ,3 )]); +sysbus_mmio_map (busdev,0 ,EXYNOS4210_MCT_BASE_ADDR ); +/*** UARTs ***/ for (n =0 ; n <EXYNOS4210_UARTS_NUMBER ; n++) {
hw/exynos4210_mct.c new file +1486 -0
1,486 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH v3 9/14 hw/exynos4210.c: Boot secondary CPU.
In reply to Evgeny Voevodin--- hw/exynos4210.c | 26 ++++++++++++++++++++++++++ 1 files changed, 26 insertions(+), 0 deletions(-)
hw/exynos4210.c +26 -0
@@ -93,8 +93,15 @@#define EXYNOS4210_EXT_COMBINER_BASE_ADDR 0x10440000#define EXYNOS4210_INT_COMBINER_BASE_ADDR 0x10448000 +/* Secondary CPU polling address to get loader start from */ +#define EXYNOS4210_SECOND_CPU_BOOTREG 0x10020814 + +/* Secondary CPU startup code is in IROM memory */ +#define EXYNOS4210_SMP_BOOT_ADDR EXYNOS4210_IROM_BASE_ADDR +static struct arm_boot_info exynos4210_binfo = { .loader_start =EXYNOS4210_BASE_BOOT_ADDR , + .smp_loader_start =EXYNOS4210_SMP_BOOT_ADDR , };static uint8_t chipid_and_omr[] = {0x11 ,0x02 ,0x21 ,0x43 ,
@@ -208,6 +215,8 @@ static void exynos4210_init(ram_addr_t ram_size,MemoryRegion *irom_alias_mem =g_new (MemoryRegion,1 );MemoryRegion *dram0_mem =g_new (MemoryRegion,1 );MemoryRegion *dram1_mem =NULL ; +MemoryRegion *hack_mem =g_new (MemoryRegion,1 ); +MemoryRegion *bootreg_mem =g_new (MemoryRegion,1 );Exynos4210Irq *irqs;qemu_irq *irq_table;qemu_irq *irqp;
@@ -221,9 +230,11 @@ static void exynos4210_init(ram_addr_t ram_size,switch (board_type) {case BOARD_EXYNOS4210_NURI : exynos4210_binfo.board_id =MACH_NURI_ID ; + exynos4210_binfo.smp_bootreg_addr =EXYNOS4210_SECOND_CPU_BOOTREG ;break ;case BOARD_EXYNOS4210_SMDKC210 : exynos4210_binfo.board_id =MACH_SMDKC210_ID ; + exynos4210_binfo.smp_bootreg_addr =EXYNOS4210_SECOND_CPU_BOOTREG ;break ;default :break ;
@@ -367,6 +378,20 @@ static void exynos4210_init(ram_addr_t ram_size,memory_region_add_subregion (system_mem,EXYNOS4210_DRAM0_BASE_ADDR , dram0_mem); +/* +* Secondary CPU startup code will be placed here. +*/ +memory_region_init_ram (hack_mem,NULL ,"exynos4210.hack" ,0x1000 ); +memory_region_add_subregion (system_mem,EXYNOS4210_SMP_BOOT_ADDR , + hack_mem); + +/* +* Hack: Map SECOND_CPU_BOOTREG, because it is in PMU USER5 register. +*/ +memory_region_init_ram (bootreg_mem,NULL ,"exynos4210.bootreg" ,0x4 ); +memory_region_add_subregion (system_mem,EXYNOS4210_SECOND_CPU_BOOTREG , + bootreg_mem); +/* CMU */ sysbus_create_simple ("exynos4210.cmu" ,EXYNOS4210_CMU_BASE_ADDR ,NULL );
@@ -441,6 +466,7 @@ static void exynos4210_init(ram_addr_t ram_size, exynos4210_binfo.kernel_filename = kernel_filename; exynos4210_binfo.initrd_filename = initrd_filename; exynos4210_binfo.kernel_cmdline = kernel_cmdline; + exynos4210_binfo.smp_priv_base =EXYNOS4210_SMP_PRIVATE_BASE_ADDR ;arm_load_kernel (first_cpu, &exynos4210_binfo); }
Signature · 1 line
1.7.4.1
PATCH v3 10/14 hw/lan9118: Add basic 16-bit mode support.
In reply to Evgeny Voevodin--- hw/devices.h | 2 +- hw/lan9118.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 109 insertions(+), 8 deletions(-)
hw/devices.h +1 -1
@@ -10,7 +10,7 @@ struct MemoryRegion;void smc91c111_init (NICInfo *,uint32_t ,qemu_irq );/* lan9118.c */ -void lan9118_init (NICInfo *,uint32_t ,qemu_irq ); +DeviceState *lan9118_init (NICInfo *,uint32_t ,qemu_irq );/* tsc210x.c */ uWireSlave *tsc2102_init (qemu_irq pint);
hw/lan9118.c +108 -7
173 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Re: [Qemu-devel] [PATCH v3 10/14] hw/lan9118: Add basic 16-bit mode support.
Quoted 12 lines · Evgeny Voevodin
Signed-off-by Evgeny Voevodin <[email protected]>---
hw/devices.h | 2 +-
hw/lan9118.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----2 files changed, 109 insertions(+), 8 deletions(-)hw/devices.h +0
-0
hw/devices.h struct MemoryRegion; · line 13
Quoted 5 lines
hw/devices.h +1
-1@@ -10,7 +10,7 @@ struct MemoryRegion; void smc91c111_init(NICInfo *, uint32_t, qemu_irq); /* lan9118.c */ -void lan9118_init (NICInfo *,uint32_t ,qemu_irq ); +DeviceState *lan9118_init (NICInfo *,uint32_t ,qemu_irq );
Don't do this. lan9118_init is just a legacy convenience function. If you need something more than what it does then just instantiate the qdev device where you use it.
In particular for your board you want to set the mode_16bit property, and properties must be set before the device has qdev_init called on it, so you can't use lan9118_init() anyway.
Quoted 100 lines
hw/devices.h +0
-0/* tsc210x.c */ uWireSlave *tsc2102_init(qemu_irq pint);hw/lan9118.c +57
-4@@ -212,6 +212,17 @@ typedef struct { int rxp_offset; int rxp_size; int rxp_pad; + + uint32_t write_word_prev_offset; + uint32_t write_word_n; + uint16_t write_word_l; + uint16_t write_word_h; + uint32_t read_word_prev_offset; + uint32_t read_word_n; + uint32_t read_long; + + uint32_t mode_16bit; + } lan9118_state; static void lan9118_update(lan9118_state *s)@@ -345,6 +356,9 @@ static void lan9118_reset(DeviceState *d) s->mac_mii_data = 0; s->mac_flow = 0; + s->read_word_n = 0; + s->write_word_n = 0; + phy_reset(s); s->eeprom_writable = 0;@@ -896,11 +910,11 @@ static void lan9118_tick(void *opaque) } static void lan9118_writel(void *opaque, target_phys_addr_t offset, - uint64_t val, unsigned size) + uint32_t val) { lan9118_state *s = (lan9118_state *)opaque; offset &= 0xff; - + //DPRINTF("Write reg 0x%02x = 0x%08x\n", (int)offset, val); if (offset >= 0x20 && offset < 0x40) { /* TX FIFO */@@ -1029,8 +1043,47 @@ static void lan9118_writel(void *opaque, target_phys_addr_t offset, lan9118_update(s); } -static uint64_t lan9118_readl (void *opaque,target_phys_addr_t offset, - unsigned size) +static void lan9118_writew (void *opaque,target_phys_addr_t offset, + uint32_t val) +{ + lan9118_state *s = (lan9118_state *)opaque; + offset &= 0xff; + + if (s->write_word_prev_offset != (offset & ~0x3)) { + /* New offset, reset word counter */ + s->write_word_n = 0; + s->write_word_prev_offset = offset & ~0x3; + } + + if (offset & 0x2) { + s->write_word_h = val; + } else { + s->write_word_l = val; + } + + //DPRINTF("Writew reg 0x%02x = 0x%08x\n", (int)offset, val); + s->write_word_n++; + if (s->write_word_n == 2) { + s->write_word_n = 0; + lan9118_writel(s, offset & ~3, s->write_word_l + + (s->write_word_h << 16)); + } +} + +static void lan9118_write (void *opaque,target_phys_addr_t offset, + uint64_t val, unsigned size) +{ + switch (size) { + case 2: + return lan9118_writew(opaque, offset, (uint32_t)val); + case 4: + return lan9118_writel(opaque, offset, (uint32_t)val); + } + + hw_error("lan9118_write: Bad size 0x%x\n", size); +} + +static uint32_t lan9118_readl (void *opaque,target_phys_addr_t offset) { lan9118_state *s = (lan9118_state *)opaque;@@ -1065,6 +1118,9 @@ static uint64_t lan9118_readl(void *opaque, target_phys_addr_t offset,
Quoted 7 lines
case
CSR_TX_CFG:
returns->tx_cfg;
caseCSR_HW_CFG:
+ if (s->mode_16bit) {
+ returns->hw_cfg& ~0x4;
+ }
returns->hw_cfg|0x4;
We should just set hw_cfg to include the correct value of this bit on reset (and make sure it can't be written to). Then the read function can just return s->hw_cfg without any fiddling about.
Quoted 45 lines
case
CSR_RX_DP_CTRL:
return 0;hw/lan9118.c +39
-0@@ -1103,9 +1159,51 @@ static uint64_t lan9118_readl(void *opaque, target_phys_addr_t offset, return 0; } +static uint32_t lan9118_readw (void *opaque,target_phys_addr_t offset) +{ + lan9118_state *s = (lan9118_state *)opaque; + uint32_t val; + + if (s->read_word_prev_offset != (offset & ~0x3)) { + /* New offset, reset word counter */ + s->read_word_n = 0; + s->read_word_prev_offset = offset & ~0x3; + } + + s->read_word_n++; + if (s->read_word_n == 1) { + s->read_long = lan9118_readl(s, offset & ~3); + } else { + s->read_word_n = 0; + } + + if (offset & 2) { + val = s->read_long >> 16; + } else { + val = s->read_long & 0xFFFF; + } + + //DPRINTF("Readw reg 0x%02x, val 0x%x\n", (int)offset, val); + return val; +} + +static uint64_t lan9118_read (void *opaque,target_phys_addr_t offset, + unsigned size) +{ + switch (size) { + case 2: + return lan9118_readw(opaque, offset); + case 4: + return lan9118_readl(opaque, offset); + } + + hw_error("lan9118_read: Bad size 0x%x\n", size);
hw/lan9118.c static uint64_t lan9118_readl(void *opaque, target_phys_addr_t offset, · line 1208
Quoted 10 lines
hw/lan9118.c +5
-2+ return 0; +} + static const MemoryRegionOps lan9118_mem_ops = { - .read = lan9118_readl, - .write = lan9118_writel, + .read = lan9118_read, + .write = lan9118_write, .endianness = DEVICE_NATIVE_ENDIAN, };
Don't change the MemoryRegionOps / functions for the 32 bit case. Instead have a second MemoryRegionOps lan9118_16bit_mem_ops with your functions (which should just call the lan9118_readl/writel passing 4 as the size), and register the correct MemoryRegionOps depending on the value of the mode_16bit property.
Quoted 29 lines
hw/lan9118.c +1
-0@@ -1162,6 +1260,7 @@ static SysBusDeviceInfo lan9118_info = { .qdev.reset = lan9118_reset, .qdev.props = (Property[]) { DEFINE_NIC_PROPERTIES(lan9118_state, conf), + DEFINE_PROP_UINT32("mode_16bit", lan9118_state, mode_16bit, 0), DEFINE_PROP_END_OF_LIST(), } };@@ -1173,7 +1272,7 @@ static void lan9118_register_devices(void) /* Legacy helper function. Should go away when machine config files areimplemented. */
hw/lan9118.c +1
-1-void lan9118_init (NICInfo *nd,uint32_t base,qemu_irq irq) +DeviceState *lan9118_init (NICInfo *nd,uint32_t base,qemu_irq irq){
DeviceState *dev;
SysBusDevice *s;hw/lan9118.c +2
-1@@ -1185,6 +1284,8 @@ void lan9118_init(NICInfo *nd, uint32_t base, qemu_irq irq) s = sysbus_from_qdev(dev); sysbus_mmio_map(s, 0, base); sysbus_connect_irq(s, 0, irq); + + return dev; } device_init(lan9118_register_devices) --1.7.4.1
PATCH v3 11/14 hw/exynos4210.c: Add LAN support for SMDKC210.
In reply to Evgeny VoevodinSMDKC210 uses lan9215 chip, but lan9118 in 16-bit mode seems to be enough.
--- hw/exynos4210.c | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-)
hw/exynos4210.c +18 -0
@@ -26,6 +26,8 @@#include "sysemu.h" #include "sysbus.h" #include "arm-misc.h" +#include "net.h" +#include "devices.h" #include "exec-memory.h" #include "exynos4210.h"
@@ -226,6 +228,8 @@ static void exynos4210_init(ram_addr_t ram_size,SysBusDevice *busdev;ram_addr_t mem_size;int n; +NICInfo *nd; +int done_nic =0 ;switch (board_type) {case BOARD_EXYNOS4210_NURI :
@@ -458,6 +462,20 @@ static void exynos4210_init(ram_addr_t ram_size,exynos4210_uart_create (addr, fifo_size, channel,NULL , uart_irq); } +/*** LAN adapter: this should be a 9215 but the 9118 is close enough ***/ +if (board_type ==BOARD_EXYNOS4210_SMDKC210 ) { +for (n =0 ; n < nb_nics; n++) { + nd = &nd_table[n]; + +if (!done_nic && (!nd->model || +strcmp (nd->model,"lan9118" ) ==0 )) { + dev =lan9118_init (nd,0x05000000 , +qemu_irq_invert (irq_table[exynos4210_get_irq (37 ,1 )])); +qdev_prop_set_uint32 (dev,"mode_16bit" ,1 ); + done_nic =1 ; + } + } + }/*** Load kernel ***/
Signature · 1 line
1.7.4.1
Re: [Qemu-devel] [PATCH v3 11/14] hw/exynos4210.c: Add LAN support for SMDKC210.
Quoted 38 lines · Evgeny Voevodin
SMDKC210 uses lan9215 chip, but lan9118 in 16-bit mode seems to be enough.
Signed-off-by Evgeny Voevodin <[email protected]>---
hw/exynos4210.c | 18 ++++++++++++++++++1 files changed, 18 insertions(+), 0 deletions(-)hw/exynos4210.c +4
-0@@ -26,6 +26,8 @@ #include "sysemu.h" #include "sysbus.h" #include "arm-misc.h" +#include "net.h" +#include "devices.h" #include "exec-memory.h" #include "exynos4210.h"@@ -226,6 +228,8 @@ static void exynos4210_init(ram_addr_t ram_size, SysBusDevice *busdev; ram_addr_t mem_size; int n; + NICInfo *nd; + int done_nic = 0; switch (board_type) {case
BOARD_EXYNOS4210_NURI:hw/exynos4210.c +4
-0@@ -458,6 +462,20 @@ static void exynos4210_init(ram_addr_t ram_size, exynos4210_uart_create(addr, fifo_size, channel, NULL, uart_irq); } + /*** LAN adapter: this should be a 9215 but the 9118 is close enough ***/ + if (board_type == BOARD_EXYNOS4210_SMDKC210) { + for (n = 0; n < nb_nics; n++) { + nd = &nd_table[n];
hw/exynos4210.c static void exynos4210_init(ram_addr_t ram_size, · line 478
Quoted 10 lines
hw/exynos4210.c +10
-0+ + if (!done_nic && (!nd->model || + strcmp(nd->model, "lan9118") == 0)) { + dev = lan9118_init(nd, 0x05000000, + qemu_irq_invert(irq_table[exynos4210_get_irq(37, 1)])); + qdev_prop_set_uint32(dev, "mode_16bit", 1); + done_nic = 1; + } + } + }
This whole loop is overkill for the straightforward case of "we only allow one NIC and this is it". Look at hw/vexpress.c, but basically you want:
nd = &nd_table[0];
if (nd->vlan) {
initialise lan9118 based on nd;
}As noted in previous patch, you can't set qdev properties after the device has been initialised, only before.
Quoted 7 lines
hw/exynos4210.c +0
-1/*** Load kernel ***/ --1.7.4.1
PATCH v3 12/14 hw/sd.c, hw/sd.h: add receive ready query routine to SD/MMC API
In reply to Evgeny VoevodinFrom: Mitsyanko Igor <[email protected]>
Data transfer direction between host controller and SD/MMC card is selected by host controller configuration registers, but whether we actually need or need not perform data transfer depends on type of last issued command. To avoid memorization of which type of command host controller issued the last time, we can use simple query procedures, to make sure that SD/MMC card is in the right state. The only query routine currently presented in SD/MMC card emulation is sd_data_ready(), this patch adds sd_receive_ready() routine.
--- hw/sd.c | 5 +++++ hw/sd.h | 1 + 2 files changed, 6 insertions(+), 0 deletions(-)
hw/sd.c +5 -0
@@ -1670,3 +1670,8 @@ void sd_enable(SDState *sd, int enable) { sd->enable = enable; } + +int sd_receive_ready (SDState *sd) +{ +return sd->state == sd_receivingdata_state; +}
hw/sd.h +1 -0
@@ -75,5 +75,6 @@ uint8_t sd_read_data(SDState *sd);void sd_set_cb (SDState *sd,qemu_irq readonly,qemu_irq insert);int sd_data_ready (SDState *sd);void sd_enable (SDState *sd,int enable); +int sd_receive_ready (SDState *sd);#endif /* __hw_sd_h */
Signature · 1 line
1.7.4.1
Re: [Qemu-devel] [PATCH v3 12/14] hw/sd.c, hw/sd.h: add receive ready query routine to SD/MMC API
Quoted 9 lines · Evgeny Voevodin
From: Mitsyanko Igor <[email protected]>
Data transfer direction between host controller and SD/MMC card is selected by host controller configuration registers, but whether we actually need or need not perform data transfer depends on type of last issued command. To avoid memorization of which type of command host controller issued the last time, we can use simple query procedures, to make sure that SD/MMC card is in the right state. The only query routine currently presented in SD/MMC card emulation is
sd_data_ready(), this patch addssd_receive_ready()routine.
I've thought about this a bit more and spent some time poking through the standards docs. I'm kind of suspicious of both this function and the existing sd_data_ready(). Real hardware doesn't have these signals, both ends of the sd-controller-to-card connection just do their thing and trust that the other end is in the state it is supposed to be. If you (in the controller model) don't already know whether you are OK to send/receive data then you haven't modelled some part of the controller's state properly.
In your specific case you know whether a command is a data transfer command by the Data Present Select bit that was written to the Command Register. You know whether it's read or write by the Data Transfer Direction Select bit in the Transfer Mode Register. So you don't need to ask the sd card about these things. (The controller needs to not blow up if the guest sets Data Present for a command that isn't a data transfer command, and so on, but that should mostly just work out without special code I think.)
-- PMM
Re: [Qemu-devel] [PATCH v3 12/14] hw/sd.c, hw/sd.h: add receive ready query routine to SD/MMC API
Quoted 11 lines · Peter Maydell
Quoted 9 lines · Evgeny Voevodin
From: Mitsyanko Igor <[email protected]>
Data transfer direction between host controller and SD/MMC card is selected by host controller configuration registers, but whether we actually need or need not perform data transfer depends on type of last issued command. To avoid memorization of which type of command host controller issued the last time, we can use simple query procedures, to make sure that SD/MMC card is in the right state. The only query routine currently presented in SD/MMC card emulation is
sd_data_ready(), this patch addssd_receive_ready()routine.
Quoted 8 lines
I've thought about this a bit more and spent some time poking through the standards docs. I'm kind of suspicious of both this function and the existing
sd_data_ready(). Real hardware doesn't have these signals, both ends of the sd-controller-to-card connection just do their thing and trust that the other end is in the state it is supposed to be. If you (in the controller model) don't already know whether you are OK to send/receive data then you haven't modelled some part of the controller's state properly.
Having thought even more :-), sd_data_ready() is actually modelling a real hardware behaviour: "have we seen the start bit on the data line?". So it is justifiable. I still don't think sd_receive_ready() is, though.
-- PMM
Re: [Qemu-devel] [PATCH v3 12/14] hw/sd.c, hw/sd.h: add receive ready query routine to SD/MMC API
Quoted 21 lines · Peter Maydell
Quoted 11 lines · Peter Maydell
Quoted 9 lines · Evgeny Voevodin
From: Mitsyanko Igor<[email protected]>
Data transfer direction between host controller and SD/MMC card is selected by host controller configuration registers, but whether we actually need or need not perform data transfer depends on type of last issued command. To avoid memorization of which type of command host controller issued the last time, we can use simple query procedures, to make sure that SD/MMC card is in the right state. The only query routine currently presented in SD/MMC card emulation is
sd_data_ready(), this patch addssd_receive_ready()routine.Quoted 8 lines
I've thought about this a bit more and spent some time poking through the standards docs. I'm kind of suspicious of both this function and the existing
sd_data_ready(). Real hardware doesn't have these signals, both ends of the sd-controller-to-card connection just do their thing and trust that the other end is in the state it is supposed to be. If you (in the controller model) don't already know whether you are OK to send/receive data then you haven't modelled some part of the controller's state properly.
Quoted 7 lines
Having thought even more :-),
sd_data_ready()is actually modelling a real hardware behaviour: "have we seen the start bit on the data line?". So it is justifiable. I still don't thinksd_receive_ready()is, though.-- PMM
I thought it's a good idea to protect user data from corruption because of inappropriate driver behaviour, even though it's obviously not a controller's concern. But after your comment about start bit it started to make sense to me that sd_data_ready() exists in current implementation, while other query functions don't :)
PATCH v3 13/14 ARM: exynos4210: added SD/MMC host controller
In reply to Evgeny VoevodinFrom: Mitsyanko Igor <[email protected]>
--- Makefile.target | 3 +- hw/exynos4210.c | 20 + hw/exynos4210_sdhc.c | 1666 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1688 insertions(+), 1 deletions(-) create mode 100644 hw/exynos4210_sdhc.c
Makefile.target +2 -1
@@ -345,7 +345,8 @@ obj-arm-y += arm_boot.o pl011.o pl031.o pl050.o pl080.o pl110.o pl181.o pl190.o obj-arm-y += versatile_pci.o obj-arm-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.o obj-arm-y += exynos4210.o exynos4210_cmu.o exynos4210_uart.o exynos4210_gic.o \ - exynos4210_combiner.o exynos4210_pwm.o exynos4210_mct.o + exynos4210_combiner.o exynos4210_pwm.o exynos4210_mct.o \ + exynos4210_sdhc.o obj-arm-y += armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o obj-arm-y += pl061.o obj-arm-y += arm-semi.o
hw/exynos4210.c +20 -0
@@ -95,6 +95,12 @@#define EXYNOS4210_EXT_COMBINER_BASE_ADDR 0x10440000#define EXYNOS4210_INT_COMBINER_BASE_ADDR 0x10448000 +/* SD/MMC host controllers SFR base addresses */ +#define EXYNOS4210_SDHC0_BASE_ADDR 0x12510000 +#define EXYNOS4210_SDHC1_BASE_ADDR 0x12520000 +#define EXYNOS4210_SDHC2_BASE_ADDR 0x12530000 +#define EXYNOS4210_SDHC3_BASE_ADDR 0x12540000 +/* Secondary CPU polling address to get loader start from */ #define EXYNOS4210_SECOND_CPU_BOOTREG 0x10020814
@@ -462,6 +468,20 @@ static void exynos4210_init(ram_addr_t ram_size,exynos4210_uart_create (addr, fifo_size, channel,NULL , uart_irq); } +/*** SD/MMC host controllers ***/ + +sysbus_create_simple ("exynos4210.sdhc" ,EXYNOS4210_SDHC0_BASE_ADDR , + irq_table[exynos4210_get_irq (29 ,0 )]); + +sysbus_create_simple ("exynos4210.sdhc" ,EXYNOS4210_SDHC1_BASE_ADDR , + irq_table[exynos4210_get_irq (29 ,1 )]); + +sysbus_create_simple ("exynos4210.sdhc" ,EXYNOS4210_SDHC2_BASE_ADDR , + irq_table[exynos4210_get_irq (29 ,2 )]); + +sysbus_create_simple ("exynos4210.sdhc" ,EXYNOS4210_SDHC3_BASE_ADDR , + irq_table[exynos4210_get_irq (29 ,3 )]); +/*** LAN adapter: this should be a 9215 but the 9118 is close enough ***/ if (board_type ==BOARD_EXYNOS4210_SMDKC210 ) {for (n =0 ; n < nb_nics; n++) {
hw/exynos4210_sdhc.c new file +1666 -0
1,666 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Re: [Qemu-devel] [PATCH v3 13/14] ARM: exynos4210: added SD/MMC host controller
hw/exynos4210_sdhc.c line 3
Quoted 6 lines · Evgeny Voevodin
hw/exynos4210_sdhc.c new file +3
-0@@ -0,0 +1,1666 @@ +/* +* Samsung exynos4210 SD/MMC host controller +* (SD host controller specification ver. 2.0 compliant)
Is there anything in this implementation which is exynos specific, or is it purely an implementation of the standard?
We should separate out (and name appropriately) the code which is implementing the SD host standard specification, and if necessary add a thin wrapper for any exynos-specific bits.
-- PMM
Re: [Qemu-devel] [PATCH v3 13/14] ARM: exynos4210: added SD/MMC host controller
Quoted 14 lines · Peter Maydell
hw/exynos4210_sdhc.c line 3
Quoted 6 lines · Evgeny Voevodin
hw/exynos4210_sdhc.c new file +3
-0@@ -0,0 +1,1666 @@ +/* +* Samsung exynos4210 SD/MMC host controller +* (SD host controller specification ver. 2.0 compliant) Is there anything in this implementation which is exynos specific, or is it purely an implementation of the standard?
We should separate out (and name appropriately) the code which is implementing the SD host standard specification, and if necessary add a thin wrapper for any exynos-specific bits.
Quoted 3 lines
-- PMM
Yes, exynos SD host controller has additional features controlled by exynos-specific bits in several specification-defined registers, and by registers CONTROL2 and CONTROL3 (which are not defined in SD host controller specification at all).
Are you suggesting to implement something like layered device, when device-specific SD host controller state structure includes generic host controller state? I thought about replacing exynos-specific registers in sd host controller state with two variables holding pointer to and size of these exynos-specific (or any other device specific) registers, plus add extra variable to hold host controller variant. This way it should be easier to account for influence of device sd host controller specific bits to default specification-defined registers behaviour.
PATCH v3 14/14 ARM: exynos4210: added display controller implementation
In reply to Evgeny VoevodinFrom: Mitsyanko Igor <[email protected]>
Exynos4210 display controller (FIMD) supports up to 5 hardware windows, along with alpha and chromakey blending capabilities.
--- Makefile.target | 2 +- hw/exynos4210.c | 11 + hw/exynos4210_fimd.c | 1737 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1749 insertions(+), 1 deletions(-) create mode 100644 hw/exynos4210_fimd.c
Makefile.target +1 -1
@@ -346,7 +346,7 @@ obj-arm-y += versatile_pci.o obj-arm-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.o obj-arm-y += exynos4210.o exynos4210_cmu.o exynos4210_uart.o exynos4210_gic.o \ exynos4210_combiner.o exynos4210_pwm.o exynos4210_mct.o \ - exynos4210_sdhc.o + exynos4210_sdhc.o exynos4210_fimd.o obj-arm-y += armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o obj-arm-y += pl061.o obj-arm-y += arm-semi.o
hw/exynos4210.c +11 -0
@@ -101,6 +101,10 @@#define EXYNOS4210_SDHC2_BASE_ADDR 0x12530000#define EXYNOS4210_SDHC3_BASE_ADDR 0x12540000 +/* Display controllers (FIMD) */ +#define EXYNOS4210_FIMD0_BASE_ADDR 0x11C00000 +#define EXYNOS4210_FIMD1_BASE_ADDR 0x12000000 +/* Secondary CPU polling address to get loader start from */ #define EXYNOS4210_SECOND_CPU_BOOTREG 0x10020814
@@ -497,6 +501,13 @@ static void exynos4210_init(ram_addr_t ram_size, } } +/*** Display controller (FIMD) ***/ +sysbus_create_varargs ("exynos4210.fimd" ,EXYNOS4210_FIMD0_BASE_ADDR , + irq_table[exynos4210_get_irq (11 ,0 )], + irq_table[exynos4210_get_irq (11 ,1 )], + irq_table[exynos4210_get_irq (11 ,2 )], +NULL ); +/*** Load kernel ***/ exynos4210_binfo.ram_size = ram_size;
hw/exynos4210_fimd.c new file +1737 -0
1,737 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Am 12.12.2011 07:43, schrieb Evgeny Voevodin:
Quoted 45 lines
This set of patches adds support for Samsung S5PC210-based boards NURI and SMDKC210. Tested on Linux kernel v3.x series. Usage of "-smp 2" option is reuired for now.
Third version: Reverted
hw/arm_gic.cmodification. Added IRQ Gate to Exynos4210 board.Evgeny Voevodin (8):
hw/sysbus.h: Increase maximum number of device IRQs.
ARM: exynos4210: IRQ subsystem support.
ARM: exynos4210: PWM support.hw/arm_boot.c: Add new secondary CPU bootloader.
ARM: exynos4210: MCT support.hw/exynos4210.c: Boot secondary CPU. hw/lan9118: Add basic 16-bit mode support.hw/exynos4210.c: Add LAN support for SMDKC210.Maksim Kozlov (3):
ARM: Samsung exynos4210-based boards emulation
ARM: exynos4210: CMU support
ARM: exynos4210: UART supportMitsyanko Igor (3):
hw/sd.c,hw/sd.h: add receive ready query routine to SD/MMC API
ARM: exynos4210: added SD/MMC host controller
ARM: exynos4210: added display controller implementationMakefile.target | 3 +
hw/arm-misc.h| 1 +hw/arm_boot.c| 22 +-hw/devices.h| 2 +-hw/exynos4210.c| 561 +++++++++++++++hw/exynos4210.h| 107 +++hw/exynos4210_cmu.c| 1146 ++++++++++++++++++++++++++++++hw/exynos4210_combiner.c| 385 ++++++++++hw/exynos4210_fimd.c| 1737 ++++++++++++++++++++++++++++++++++++++++++++++hw/exynos4210_gic.c | 510 ++++++++++++++ hw/exynos4210_mct.c | 1486 +++++++++++++++++++++++++++++++++++++++ hw/exynos4210_pwm.c | 433 ++++++++++++
hw/exynos4210_sdhc.c| 1666 ++++++++++++++++++++++++++++++++++++++++++++hw/exynos4210_uart.c| 674 ++++++++++++++++++hw/lan9118.c| 115 +++-hw/sd.c| 5 +hw/sd.h| 1 +hw/sysbus.h| 2 +-18 files changed, 8840 insertions(+), 16 deletions(-)
Quoted 10 lines
create mode 100644
hw/exynos4210.c
create mode 100644hw/exynos4210.h
create mode 100644hw/exynos4210_cmu.c
create mode 100644hw/exynos4210_combiner.c
create mode 100644hw/exynos4210_fimd.c
create mode 100644hw/exynos4210_gic.c
create mode 100644hw/exynos4210_mct.c
create mode 100644hw/exynos4210_pwm.c
create mode 100644hw/exynos4210_sdhc.c
create mode 100644hw/exynos4210_uart.c
I did not review you patches, but noticed that they still include the FSF address (which changed several times in the past):
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation,
Inc., 51
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
To avoid future address change modifications, most QEMU code uses this statement in the license comments:
You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.
If a new version of your patches is needed, you might change that as well.
Regards,
Stefan Weil
Quoted 2 lines · Evgeny Voevodin
This set of patches adds support for Samsung S5PC210-based boards NURI and SMDKC210. Tested on Linux kernel v3.x series. Usage of "-smp 2" option is reuired for now.
General question -- is there publicly available hardware documentation for this SoC ?
-- PMM
Dear Peter,
Public Exynos4210 UM is available at http://www.samsung.com/global/system/business/semiconductor/product/2011/12/2/738994Pulbicmanual_Exynos4210_Ver00001.pdf
Thanks,
Dmitry Solodkiy,
Mobile SW PL, Advanced Software Group,
Moscow R&D center, Samsung Electronics
-----Original Message-----
From: Peter Maydell [mailto:[email protected]]
Sent: Tuesday, December 13, 2011 2:15 PM
To: Evgeny Voevodin
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [Qemu-devel] [PATCH v3 00/14] ARM: Samsung Exynos4210-based boards support.
Quoted 2 lines · Evgeny Voevodin
This set of patches adds support for Samsung S5PC210-based boards NURI and SMDKC210. Tested on Linux kernel v3.x series. Usage of "-smp 2" option is reuired for now.
General question -- is there publicly available hardware documentation for this SoC ?
-- PMM
Quoted 3 lines · Dmitry Solodkiy
Dear Peter,
Public Exynos4210 UM is available at http://www.samsung.com/global/system/business/semiconductor/product/2011/12/2/738994Pulbicmanual_Exynos4210_Ver00001.pdf
Thanks. It seems to be missing some info though -- for example your model instantiates both an "internal interrupt combiner" and an "external interrupt combiner", but that PDF documents only the external one...
-- PMM