bcm2835_armtimer: add bcm2835 ARM timer
Subsystems (2)
PATCH 1/1 bcm2835_armtimer: add bcm2835 ARM timer
The ARM Timer is based on a ARM AP804, but it has
a number of differences with the standard SP804.
There is only one timer which runs in continuous
mode with an extra clock pre-divider register
and a 32-bit free running counter.
The extra stop-in-debug-mode control bit is not
implemented.
--- hw/arm/bcm2835_peripherals.c | 18 +++ hw/timer/Makefile.objs | 1 + hw/timer/bcm2835_armtimer.c | 271 +++++++++++++++++++++++++++++++++++ hw/timer/trace-events | 4 + include/hw/arm/bcm2835_peripherals.h | 2 + include/hw/timer/bcm2835_armtimer.h | 35 +++++ 6 files changed, 331 insertions(+) create mode 100644 hw/timer/bcm2835_armtimer.c create mode 100644 include/hw/timer/bcm2835_armtimer.h
hw/arm/bcm2835_peripherals.c +18 -0
@@ -90,6 +90,11 @@ static void bcm2835_peripherals_init(Object *obj)object_property_add_child (obj,"rng" ,OBJECT (&s->rng),NULL );qdev_set_parent_bus (DEVICE (&s->rng),sysbus_get_default ()); +/* ARM Timer */ +object_initialize (&s->armtimer,sizeof (s->armtimer),TYPE_BCM2835_ARMTIMER ); +object_property_add_child (obj,"armtimer" ,OBJECT (&s->armtimer),NULL ); +qdev_set_parent_bus (DEVICE (&s->armtimer),sysbus_get_default ()); +/* Extended Mass Media Controller */ object_initialize (&s->sdhci,sizeof (s->sdhci),TYPE_SYSBUS_SDHCI );object_property_add_child (obj,"sdhci" ,OBJECT (&s->sdhci),NULL );
@@ -254,6 +259,19 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)memory_region_add_subregion (&s->peri_mr,RNG_OFFSET ,sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->rng),0 )); +/* ARM Timer */ +object_property_set_bool (OBJECT (&s->armtimer), true,"realized" , &err); +if (err) { +error_propagate (errp, err); +return ; + } + +memory_region_add_subregion (&s->peri_mr,ARMCTRL_TIMER0_1_OFFSET , +sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->armtimer),0 )); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->armtimer),0 , +qdev_get_gpio_in_named (DEVICE (&s->ic),BCM2835_IC_ARM_IRQ , +INTERRUPT_ARM_TIMER )); +/* Extended Mass Media Controller */ object_property_set_int (OBJECT (&s->sdhci),BCM2835_SDHC_CAPAREG ,"capareg" , &err);
hw/timer/Makefile.objs +1 -0
@@ -29,6 +29,7 @@ obj-$(CONFIG_EXYNOS4) += exynos4210_rtc.o obj-$(CONFIG_OMAP) += omap_gptimer.o obj-$(CONFIG_OMAP) += omap_synctimer.o obj-$(CONFIG_PXA2XX) += pxa2xx_timer.o +obj-$(CONFIG_RASPI) += bcm2835_armtimer.o obj-$(CONFIG_SH4) += sh_timer.o obj-$(CONFIG_DIGIC) += digic-timer.o obj-$(CONFIG_MIPS_CPS) += mips_gictimer.o
hw/timer/bcm2835_armtimer.c new file +271 -0
271 lines not on this page · raw message
hw/timer/trace-events +4 -0
@@ -60,3 +60,7 @@ systick_write(uint64_t addr, uint32_t value, unsigned size) "systick write addr cmsdk_apb_timer_read(uint64_t offset, uint64_t data, unsigned size) "CMSDK APB timer read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" cmsdk_apb_timer_write(uint64_t offset, uint64_t data, unsigned size) "CMSDK APB timer write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" cmsdk_apb_timer_reset(void) "CMSDK APB timer: reset" + +# hw/timer/bcm2535_armtimer.c +bcm2835_armtimer_interrupt(void) "irq" +bcm2835_armtimer_ack(void) "ack"
include/hw/arm/bcm2835_peripherals.h +2 -0
@@ -20,6 +20,7 @@#include "hw/intc/bcm2835_ic.h" #include "hw/misc/bcm2835_property.h" #include "hw/misc/bcm2835_rng.h" +#include "hw/timer/bcm2835_armtimer.h" #include "hw/misc/bcm2835_mbox.h" #include "hw/sd/sdhci.h" #include "hw/sd/bcm2835_sdhost.h"
@@ -43,6 +44,7 @@ typedef struct BCM2835PeripheralState {BCM2835FBState fb;BCM2835DMAState dma;BCM2835ICState ic; +BCM2835ARMTimerState armtimer;BCM2835PropertyState property;BCM2835RngState rng;BCM2835MboxState mboxes;
include/hw/timer/bcm2835_armtimer.h new file +35 -0
@@ -0,0 +1,35 @@ +/* +* BCM2835 ARM Timer +* +* Copyright (C) 2017 Thomas Venriès <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef BCM2835_ARMTIMER_H +#define BCM2835_ARMTIMER_H + +#include "hw/ptimer.h" +#include "hw/sysbus.h" + +#define TYPE_BCM2835_ARMTIMER "bcm2835-armtimer" +#define BCM2835_ARMTIMER (obj) \ + OBJECT_CHECK(BCM2835ARMTimerState, (obj), TYPE_BCM2835_ARMTIMER) + +typedef struct { +SysBusDevice parent_obj; +MemoryRegion iomem; + +ptimer_state *timer; +qemu_irq irq; + +uint32_t ctrl; +uint32_t raw_irq; +uint32_t msk_irq; +uint32_t reload; +uint32_t prediv; +uint32_t prescaler; +}BCM2835ARMTimerState ; + +#endif
Signature · 1 line
2.7.4
This series seems to have some coding style problems. See output below for more information:
Hi,
This series seems to have some coding style problems. See output below for more information:
Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH] bcm2835_armtimer: add bcm2835 ARM timer
=== TEST SCRIPT BEGIN ===
#!/bin/bash
BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0
git config --local diff.renamelimit 0
git config --local diff.renames True
commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))done
exit $failed
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 Switched to a new branch 'test'fd596b541c bcm2835_armtimer: add bcm2835 ARM timer
=== OUTPUT BEGIN ===
Checking PATCH 1/1: bcm2835_armtimer: add bcm2835 ARM timer...
ERROR: space prohibited before open square bracket '[' #147: FILE: hw/timer/bcm2835_armtimer.c:73:
+static const uint16_t ctrl_prescale [] = { 1, 16, 256, 1 };
ERROR: return is not a function, parentheses are not required #195: FILE: hw/timer/bcm2835_armtimer.c:121:
+ return (s->raw_irq && (s->ctrl & CTRL_INT_ENABLE));
ERROR: braces {} are necessary for all arms of this statement #220: FILE: hw/timer/bcm2835_armtimer.c:146:
+ if (s->ctrl & CTRL_TIMER_ENABLE)
[...]
ERROR: braces {} are necessary for all arms of this statement #234: FILE: hw/timer/bcm2835_armtimer.c:160:
+ if (s->ctrl & CTRL_TIMER_ENABLE)
[...]
total: 4 errors, 0 warnings, 364 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]
PATCH v2 1/1 bcm2835_armtimer: add bcm2835 ARM timer
The ARM Timer is based on a ARM AP804, but it has
a number of differences with the standard SP804.
There is only one timer which runs in continuous
mode with an extra clock pre-divider register
and a 32-bit free running counter.
The extra stop-in-debug-mode control bit is not
implemented.
--- hw/arm/bcm2835_peripherals.c | 18 +++ hw/timer/Makefile.objs | 1 + hw/timer/bcm2835_armtimer.c | 273 +++++++++++++++++++++++++++++++++++ hw/timer/trace-events | 4 + include/hw/arm/bcm2835_peripherals.h | 2 + include/hw/timer/bcm2835_armtimer.h | 35 +++++ 6 files changed, 333 insertions(+) create mode 100644 hw/timer/bcm2835_armtimer.c create mode 100644 include/hw/timer/bcm2835_armtimer.h
hw/arm/bcm2835_peripherals.c +18 -0
@@ -90,6 +90,11 @@ static void bcm2835_peripherals_init(Object *obj)object_property_add_child (obj,"rng" ,OBJECT (&s->rng),NULL );qdev_set_parent_bus (DEVICE (&s->rng),sysbus_get_default ()); +/* ARM Timer */ +object_initialize (&s->armtimer,sizeof (s->armtimer),TYPE_BCM2835_ARMTIMER ); +object_property_add_child (obj,"armtimer" ,OBJECT (&s->armtimer),NULL ); +qdev_set_parent_bus (DEVICE (&s->armtimer),sysbus_get_default ()); +/* Extended Mass Media Controller */ object_initialize (&s->sdhci,sizeof (s->sdhci),TYPE_SYSBUS_SDHCI );object_property_add_child (obj,"sdhci" ,OBJECT (&s->sdhci),NULL );
@@ -254,6 +259,19 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)memory_region_add_subregion (&s->peri_mr,RNG_OFFSET ,sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->rng),0 )); +/* ARM Timer */ +object_property_set_bool (OBJECT (&s->armtimer), true,"realized" , &err); +if (err) { +error_propagate (errp, err); +return ; + } + +memory_region_add_subregion (&s->peri_mr,ARMCTRL_TIMER0_1_OFFSET , +sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->armtimer),0 )); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->armtimer),0 , +qdev_get_gpio_in_named (DEVICE (&s->ic),BCM2835_IC_ARM_IRQ , +INTERRUPT_ARM_TIMER )); +/* Extended Mass Media Controller */ object_property_set_int (OBJECT (&s->sdhci),BCM2835_SDHC_CAPAREG ,"capareg" , &err);
hw/timer/Makefile.objs +1 -0
@@ -29,6 +29,7 @@ obj-$(CONFIG_EXYNOS4) += exynos4210_rtc.o obj-$(CONFIG_OMAP) += omap_gptimer.o obj-$(CONFIG_OMAP) += omap_synctimer.o obj-$(CONFIG_PXA2XX) += pxa2xx_timer.o +obj-$(CONFIG_RASPI) += bcm2835_armtimer.o obj-$(CONFIG_SH4) += sh_timer.o obj-$(CONFIG_DIGIC) += digic-timer.o obj-$(CONFIG_MIPS_CPS) += mips_gictimer.o
hw/timer/bcm2835_armtimer.c new file +273 -0
273 lines not on this page · raw message
hw/timer/trace-events +4 -0
@@ -60,3 +60,7 @@ systick_write(uint64_t addr, uint32_t value, unsigned size) "systick write addr cmsdk_apb_timer_read(uint64_t offset, uint64_t data, unsigned size) "CMSDK APB timer read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" cmsdk_apb_timer_write(uint64_t offset, uint64_t data, unsigned size) "CMSDK APB timer write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" cmsdk_apb_timer_reset(void) "CMSDK APB timer: reset" + +# hw/timer/bcm2535_armtimer.c +bcm2835_armtimer_interrupt(void) "irq" +bcm2835_armtimer_ack(void) "ack"
include/hw/arm/bcm2835_peripherals.h +2 -0
@@ -20,6 +20,7 @@#include "hw/intc/bcm2835_ic.h" #include "hw/misc/bcm2835_property.h" #include "hw/misc/bcm2835_rng.h" +#include "hw/timer/bcm2835_armtimer.h" #include "hw/misc/bcm2835_mbox.h" #include "hw/sd/sdhci.h" #include "hw/sd/bcm2835_sdhost.h"
@@ -43,6 +44,7 @@ typedef struct BCM2835PeripheralState {BCM2835FBState fb;BCM2835DMAState dma;BCM2835ICState ic; +BCM2835ARMTimerState armtimer;BCM2835PropertyState property;BCM2835RngState rng;BCM2835MboxState mboxes;
include/hw/timer/bcm2835_armtimer.h new file +35 -0
@@ -0,0 +1,35 @@ +/* +* BCM2835 ARM Timer +* +* Copyright (C) 2017 Thomas Venriès <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef BCM2835_ARMTIMER_H +#define BCM2835_ARMTIMER_H + +#include "hw/ptimer.h" +#include "hw/sysbus.h" + +#define TYPE_BCM2835_ARMTIMER "bcm2835-armtimer" +#define BCM2835_ARMTIMER (obj) \ + OBJECT_CHECK(BCM2835ARMTimerState, (obj), TYPE_BCM2835_ARMTIMER) + +typedef struct { +SysBusDevice parent_obj; +MemoryRegion iomem; + +ptimer_state *timer; +qemu_irq irq; + +uint32_t ctrl; +uint32_t raw_irq; +uint32_t msk_irq; +uint32_t reload; +uint32_t prediv; +uint32_t prescaler; +}BCM2835ARMTimerState ; + +#endif
--
2.7.4
Quoted 113 lines · Thomas Venriès
The ARM Timer is based on a ARM AP804, but it has
a number of differences with the standard SP804.
There is only one timer which runs in continuous
mode with an extra clock pre-divider register
and a 32-bit free running counter.The extra stop-in-debug-mode control bit is not
implemented.Signed-off-by Thomas Venriès <[email protected]>--- hw/arm/bcm2835_peripherals.c | 18 +++ hw/timer/Makefile.objs | 1 + hw/timer/bcm2835_armtimer.c | 273 +++++++++++++++++++++++++++++++++++ hw/timer/trace-events | 4 + include/hw/arm/bcm2835_peripherals.h | 2 + include/hw/timer/bcm2835_armtimer.h | 35 +++++ 6 files changed, 333 insertions(+) create mode 100644 hw/timer/bcm2835_armtimer.c create mode 100644 include/hw/timer/bcm2835_armtimer.hhw/arm/bcm2835_peripherals.c +18
-0@@ -90,6 +90,11 @@ static void bcm2835_peripherals_init(Object *obj)object_property_add_child (obj,"rng" ,OBJECT (&s->rng),NULL );qdev_set_parent_bus (DEVICE (&s->rng),sysbus_get_default ()); +/* ARM Timer */ +object_initialize (&s->armtimer,sizeof (s->armtimer),TYPE_BCM2835_ARMTIMER ); +object_property_add_child (obj,"armtimer" ,OBJECT (&s->armtimer),NULL ); +qdev_set_parent_bus (DEVICE (&s->armtimer),sysbus_get_default ()); +/* Extended Mass Media Controller */ object_initialize (&s->sdhci,sizeof (s->sdhci),TYPE_SYSBUS_SDHCI );object_property_add_child (obj,"sdhci" ,OBJECT (&s->sdhci),NULL );@@ -254,6 +259,19 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)memory_region_add_subregion (&s->peri_mr,RNG_OFFSET ,sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->rng),0 )); +/* ARM Timer */ +object_property_set_bool (OBJECT (&s->armtimer), true,"realized" , &err); +if (err) { +error_propagate (errp, err); +return ; + } + +memory_region_add_subregion (&s->peri_mr,ARMCTRL_TIMER0_1_OFFSET , +sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->armtimer),0 )); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->armtimer),0 , +qdev_get_gpio_in_named (DEVICE (&s->ic),BCM2835_IC_ARM_IRQ , +INTERRUPT_ARM_TIMER )); +/* Extended Mass Media Controller */ object_property_set_int (OBJECT (&s->sdhci),BCM2835_SDHC_CAPAREG ,"capareg" , &err);hw/timer/Makefile.objs +1
-0@@ -29,6 +29,7 @@ obj-$(CONFIG_EXYNOS4) += exynos4210_rtc.o obj-$(CONFIG_OMAP) += omap_gptimer.o obj-$(CONFIG_OMAP) += omap_synctimer.o obj-$(CONFIG_PXA2XX) += pxa2xx_timer.o +obj-$(CONFIG_RASPI) += bcm2835_armtimer.o obj-$(CONFIG_SH4) += sh_timer.o obj-$(CONFIG_DIGIC) += digic-timer.o obj-$(CONFIG_MIPS_CPS) += mips_gictimer.ohw/timer/bcm2835_armtimer.c new file +38
-0@@ -0,0 +1,273 @@ +/* +* BCM2835 ARM Timer +* +* Copyright (C) 2017 Thomas Venriès <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qapi/error.h" +#include "qemu/timer.h" +#include "qemu/main-loop.h" +#include "hw/ptimer.h" +#include "hw/timer/bcm2835_armtimer.h" +#include "trace.h" + +#define ARM_TIMER_REG_SIZE 0x24 + +/* Register offsets */ +#define ARM_TIMER_LOAD 0x00 +#define ARM_TIMER_VALUE 0x04 +#define ARM_TIMER_CTRL 0x08 +#define ARM_TIMER_INTCLR 0x0C +#define ARM_TIMER_RAW_IRQ 0x10 +#define ARM_TIMER_MASK_IRQ 0x14 +#define ARM_TIMER_RELOAD 0x18 +#define ARM_TIMER_PREDIVIDER 0x1C +#define ARM_TIMER_COUNTER 0x20 + +/* Control register masks */ +#define CTRL_CNT_PRESCALE (0xFF << 16) +#define CTRL_CNT_ENABLE (1 << 9) +#define CTRL_TIMER_ENABLE (1 << 7) +#define CTRL_INT_ENABLE (1 << 5) +#define CTRL_TIMER_PRESCALE (3 << 2) +#define CTRL_TIMER_SIZE_32BIT (1 << 1)
hw/timer/bcm2835_armtimer.c line 48
Quoted 10 lines
hw/timer/bcm2835_armtimer.c new file +10
-0+ +#define CTRL_TIMER_WRAP_MODE 0 + +/* Register reset values */ +#define CTRL_CNT_PRESCALE_RESET (0x3E << 16) +#define ARM_TIMER_CTRL_RESET (CTRL_CNT_PRESCALE_RESET | CTRL_INT_ENABLE) +#define ARM_TIMER_IE_READ_VALUE 0x544D5241/* ASCII "ARMT" */ +/* +The system clock refers to a 250 MHz frequency by default. +This frequency can be changed by setting `core_freq` the `config.txt` file.
What config.txt is this referring to?
Quoted 31 lines
hw/timer/bcm2835_armtimer.c new file +31
-0+APB clock runs at half the speed of the system clock also called ARM clock. + +The ARM timer's predivider register is 10 bits wide and can be written +or read from. This register has been added as the SP804 expects a 1MHz clock +which they do not have. Instead the predivider takes the APB clock +and divides it down according to: + +timer_clock = apb_clock / (prediv + 1) + +The need is a 1MHz timer clock frequency and BCM2835 ARM Peripherals +documentation mentions the predivider reset value is 0x7D (or 125), so +the APB clock refers to a 126MHz frequency. + +Also the additional free-running counter runs from the APB clock and has +its own clock predivider controlled by buts 16-23 of the timer control reg: + +frc_clock = apb_clock / (prediv + 1) + +The predivider reset value is 0x3E (or 62), knowing APB clock frequency, +the FRN clock refers to a 2MHz frequency by default. +*/ +#define ARM_APB_FREQ 126000000UL/* Hz */ +#define ARM_TIMER_PREDIVIDER_RESET 125/* MHz */ + +static const uint16_t ctrl_prescale[] = {1 ,16 ,256 ,1 }; + +static void bcm2835_armtimer_recalibrate (BCM2835ARMTimerState *s,int reload) +{ +uint32_t limit; + +/* ARM Dual-Timer Module SP804, section 3.2.1:
hw/timer/bcm2835_armtimer.c line 89
Quoted 10 lines
hw/timer/bcm2835_armtimer.c new file +10
-0+If the Load Register is set to 0 then an interrupt is generated +immediately. */ +if (reload ==2 ) { + limit = s->reload; + }else { + limit = (s->ctrl &CTRL_TIMER_SIZE_32BIT ) ?0xFFFFFFFF :0XFFFF ; + } + +ptimer_set_limit (s->timer, limit, reload); +}
This whole file is very duplicative of code with arm-timer.c. Can we implement it by adding a property to the arm_timer device that says "behave like the bcm2835 variant" ?
thanks
-- PMM