esp: refactor Espressif generic drivers to use three-stage reset instead of legacy reset

This commit is contained in:
Omar Chebib
2025-03-25 16:41:56 +08:00
parent 17207a3c3f
commit 95c74f43e2
5 changed files with 25 additions and 25 deletions
+4 -3
View File
@@ -408,9 +408,9 @@ static const MemoryRegionOps esp_aes_ops = {
.endianness = DEVICE_LITTLE_ENDIAN,
};
static void esp_aes_reset(DeviceState *dev)
static void esp_aes_reset_hold(Object *obj, ResetType type)
{
ESPAesState *s = ESP_AES(dev);
ESPAesState *s = ESP_AES(obj);
memset(s->key, 0, ESP_AES_KEY_REG_CNT * sizeof(uint32_t));
memset(s->text_in, 0, ESP_AES_TEXT_REG_CNT * sizeof(uint32_t));
memset(s->text_out, 0, ESP_AES_TEXT_REG_CNT * sizeof(uint32_t));
@@ -450,9 +450,10 @@ static void esp_aes_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
ESPAesClass* esp_aes = ESP_AES_CLASS(klass);
ResettableClass *rc = RESETTABLE_CLASS(klass);
dc->realize = esp_aes_realize;
dc->legacy_reset = esp_aes_reset;
rc->phases.hold = esp_aes_reset_hold;
esp_aes->aes_block_start = aes_block_start;
}
+9 -12
View File
@@ -46,8 +46,7 @@ static void esp_ds_generate_ds_key(ESPDsState *s)
}
// The DS peripheral resets the HMAC peripheral once it has completed the respective operation.
DeviceClass *hmac_dc = DEVICE_CLASS(hmac_class);
hmac_dc->legacy_reset((DeviceState*)(s->hmac));
resettable_reset(OBJECT(s->hmac), RESET_TYPE_S390_CPU_NORMAL);
}
static void esp_ds_decrypt_ciphertext(ESPDsState *s, uint8_t *buffer)
@@ -82,8 +81,7 @@ static void esp_ds_decrypt_ciphertext(ESPDsState *s, uint8_t *buffer)
}
// The DS peripheral resets the AES peripheral once it has completed the respective operation.
DeviceClass *aes_dc = DEVICE_CLASS(aes_class);
aes_dc->legacy_reset((DeviceState*)(s->aes));
resettable_reset(OBJECT(s->aes), RESET_TYPE_S390_CPU_NORMAL);
}
static bool md_and_pad_check(ESPDsState *s)
@@ -180,8 +178,7 @@ static bool md_and_pad_check(ESPDsState *s)
}
// The DS peripheral resets the SHA peripheral once it has completed the respective operation.
DeviceClass *sha_dc = DEVICE_CLASS(sha_class);
sha_dc->legacy_reset((DeviceState*)(s->sha));
resettable_reset(OBJECT(s->sha), RESET_TYPE_S390_CPU_NORMAL);
if (memcmp(md, md_check, SHA256_DIGEST_SIZE) == 0) {
s->ds_signature_check ^= DS_SIGNATURE_MD_FAIL;
@@ -201,8 +198,7 @@ static void esp_ds_generate_signature(ESPDsState *s)
rsa_class->rsa_exp_mod(s->rsa, mode, s->x_mem, s->y_mem, s->m_mem, s->z_mem, 0);
// The DS peripheral resets the RSA peripheral once it has completed the respective operation.
DeviceClass *rsa_dc = DEVICE_CLASS(rsa_class);
rsa_dc->legacy_reset((DeviceState*)(s->rsa));
resettable_reset(OBJECT(s->rsa), RESET_TYPE_S390_CPU_NORMAL);
}
static void esp_ds_calculate(ESPDsState *s)
@@ -382,9 +378,9 @@ static const MemoryRegionOps esp_ds_ops = {
.endianness = DEVICE_LITTLE_ENDIAN,
};
static void esp_ds_reset(DeviceState *dev)
static void esp_ds_reset_hold(Object *obj, ResetType type)
{
ESPDsState *s = ESP_DS(dev);
ESPDsState *s = ESP_DS(obj);
esp_ds_clear_buffers(s);
s->ds_signature_check = DS_SIGNATURE_PADDING_AND_MD_FAIL;
}
@@ -453,9 +449,10 @@ static void esp_ds_init(Object *obj)
static void esp_ds_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
ResettableClass *rc = RESETTABLE_CLASS(klass);
dc->realize = esp_ds_realize;
dc->legacy_reset = esp_ds_reset;
rc->phases.hold = esp_ds_reset_hold;
}
static const TypeInfo esp_ds_info = {
@@ -474,4 +471,4 @@ static void esp_ds_register_types(void)
type_register_static(&esp_ds_info);
}
type_init(esp_ds_register_types)
type_init(esp_ds_register_types)
+4 -3
View File
@@ -159,9 +159,9 @@ static const MemoryRegionOps esp_hmac_ops = {
.endianness = DEVICE_LITTLE_ENDIAN,
};
static void esp_hmac_reset(DeviceState *dev)
static void esp_hmac_reset_hold(Object *obj, ResetType type)
{
ESPHmacState *s = ESP_HMAC(dev);
ESPHmacState *s = ESP_HMAC(obj);
memset(s->message, 0, sizeof(s->message));
memset(s->result, 0, sizeof(s->result));
@@ -194,9 +194,10 @@ static void esp_hmac_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
ESPHmacClass* esp_hmac = ESP_HMAC_CLASS(klass);
ResettableClass *rc = RESETTABLE_CLASS(klass);
dc->realize = esp_hmac_realize;
dc->legacy_reset = esp_hmac_reset;
rc->phases.hold = esp_hmac_reset_hold;
esp_hmac->hmac_update = esp_hmac_update;
esp_hmac->hmac_finish = esp_hmac_finish;
+4 -4
View File
@@ -409,9 +409,9 @@ static const MemoryRegionOps esp_rsa_ops = {
.endianness = DEVICE_LITTLE_ENDIAN,
};
static void esp_rsa_reset(DeviceState *dev)
static void esp_rsa_reset_hold(Object *obj, ResetType type)
{
ESPRsaState *s = ESP_RSA(dev);
ESPRsaState *s = ESP_RSA(obj);
esp_rsa_clean_mem(s);
@@ -434,10 +434,10 @@ static void esp_rsa_init(Object *obj)
static void esp_rsa_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
ESPRsaClass* esp_rsa = ESP_RSA_CLASS(klass);
ResettableClass *rc = RESETTABLE_CLASS(klass);
dc->legacy_reset = esp_rsa_reset;
rc->phases.hold = esp_rsa_reset_hold;
esp_rsa->rsa_exp_mod = esp_rsa_exp_mod;
}
+4 -3
View File
@@ -319,9 +319,9 @@ static const MemoryRegionOps esp_sha_ops = {
};
static void esp_sha_reset(DeviceState *dev)
static void esp_sha_reset_hold(Object *obj, ResetType type)
{
ESPShaState *s = ESP_SHA(dev);
ESPShaState *s = ESP_SHA(obj);
memset(s->hash, 0, 8 * sizeof(uint32_t));
memset(s->message, 0, ESP_SHA_MAX_MESSAGE_WORDS * sizeof(uint32_t));
@@ -358,9 +358,10 @@ static void esp_sha_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
ESPShaClass* esp_sha = ESP_SHA_CLASS(klass);
ResettableClass *rc = RESETTABLE_CLASS(klass);
dc->realize = esp_sha_realize;
dc->legacy_reset = esp_sha_reset;
rc->phases.hold = esp_sha_reset_hold;
esp_sha->sha_start = esp_sha_start;
}