hw/timer: implement ESP32-S3 System Timer
Co-authored-by: Omar Chebib <omar.chebib@espressif.com>
This commit is contained in:
committed by
Ivan Grokhotkov
parent
c3a794405a
commit
79eb790ebe
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* ESP32-S3 System Timer
|
||||
*
|
||||
* Copyright (c) 2024 Espressif Systems (Shanghai) Co. Ltd.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
#include "qemu/osdep.h"
|
||||
#include "hw/hw.h"
|
||||
#include "hw/sysbus.h"
|
||||
#include "hw/registerfields.h"
|
||||
#include "hw/boards.h"
|
||||
#include "hw/timer/esp32s3_systimer.h"
|
||||
|
||||
|
||||
static void esp32c3_systimer_write(void *opaque, hwaddr addr, uint64_t value, unsigned int size)
|
||||
{
|
||||
ESP32S3SysTimerClass *class = ESP32S3_SYSTIMER_GET_CLASS(opaque);
|
||||
ESP32S3SysTimerState *s = ESP32S3_SYSTIMER(opaque);
|
||||
|
||||
class->parent_systimer_write(opaque, addr, value, size);
|
||||
|
||||
if (addr == A_SYSTIMER_INT_ENA) {
|
||||
/* If the timer virtual interrupt is enabled too late, we may miss the interrupt in QEMU
|
||||
* and not reprogram the next iteration. */
|
||||
class->parent_class.comparators_reprogram(&s->parent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void esp32s3_systimer_class_init(ObjectClass *klass, void *data)
|
||||
{
|
||||
ESP32S3SysTimerClass* esp32s3 = ESP32S3_SYSTIMER_CLASS(klass);
|
||||
ESPSysTimerClass* esp = ESP_SYSTIMER_CLASS(klass);
|
||||
|
||||
/* Override the register read method */
|
||||
esp32s3->parent_systimer_write = esp->systimer_ops.write;
|
||||
esp->systimer_ops.write = esp32c3_systimer_write;
|
||||
}
|
||||
|
||||
|
||||
static const TypeInfo esp32s3_systimer_info = {
|
||||
.name = TYPE_ESP32S3_SYSTIMER,
|
||||
.parent = TYPE_ESP_SYSTIMER,
|
||||
.instance_size = sizeof(ESP32S3SysTimerState),
|
||||
.class_init = esp32s3_systimer_class_init,
|
||||
.class_size = sizeof(ESP32S3SysTimerClass),
|
||||
};
|
||||
|
||||
|
||||
static void esp32s3_systimer_register_types(void)
|
||||
{
|
||||
type_register_static(&esp32s3_systimer_info);
|
||||
}
|
||||
|
||||
|
||||
type_init(esp32s3_systimer_register_types)
|
||||
@@ -38,6 +38,8 @@ system_ss.add(when: 'CONFIG_RISCV_ESP32C3', if_true: files(
|
||||
))
|
||||
system_ss.add(when: 'CONFIG_XTENSA_ESP32S3', if_true: files(
|
||||
'esp32c3_timg.c',
|
||||
'esp_systimer.c',
|
||||
'esp32s3_systimer.c'
|
||||
))
|
||||
specific_ss.add(when: 'CONFIG_IBEX', if_true: files('ibex_timer.c'))
|
||||
system_ss.add(when: 'CONFIG_SIFIVE_PWM', if_true: files('sifive_pwm.c'))
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* ESP32-S3 System Timer emulation
|
||||
*
|
||||
* Copyright (c) 2024 Espressif Systems (Shanghai) Co. Ltd.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "hw/hw.h"
|
||||
#include "hw/registerfields.h"
|
||||
#include "hw/timer/esp_systimer.h"
|
||||
|
||||
#define TYPE_ESP32S3_SYSTIMER "esp32s3.systimer"
|
||||
#define ESP32S3_SYSTIMER(obj) OBJECT_CHECK(ESP32S3SysTimerState, (obj), TYPE_ESP32S3_SYSTIMER)
|
||||
#define ESP32S3_SYSTIMER_GET_CLASS(obj) OBJECT_GET_CLASS(ESP32S3SysTimerClass, obj, TYPE_ESP32S3_SYSTIMER)
|
||||
#define ESP32S3_SYSTIMER_CLASS(klass) OBJECT_CLASS_CHECK(ESP32S3SysTimerClass, (klass), TYPE_ESP32S3_SYSTIMER)
|
||||
|
||||
|
||||
typedef struct ESP32S3SysTimerState {
|
||||
ESPSysTimerState parent;
|
||||
} ESP32S3SysTimerState;
|
||||
|
||||
|
||||
typedef struct ESP32S3SysTimerClass {
|
||||
ESPSysTimerClass parent_class;
|
||||
|
||||
/* Virtual attributes/methods overriden */
|
||||
void (*parent_systimer_write)(void *opaque, hwaddr addr, uint64_t value, unsigned int size);
|
||||
} ESP32S3SysTimerClass;
|
||||
Reference in New Issue
Block a user