On 3/21/25 10:26, Jamin Lin wrote:
> The memory size was previously hardcoded to 0x1000 (4K). However, the actual
> memory size of the HACE controller varies across different models:
> 1. AST2400/AST2500: 0x1000 (4K)
> 2. AST2600/AST1030: 0x10000 (64K)
> 3. AST2700: 0x100 (256 bytes)
>
> To address this, a new class attribute, mem_size, has been introduced to
> dynamically set the appropriate memory size for each HACE model, ensuring
> correct allocation across AST2400, AST2500, AST2600, AST1030 and AST2700.
>
> Signed-off-by: Jamin Lin <jamin_lin@aspeedtech.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Thanks,
C.
> ---
> include/hw/misc/aspeed_hace.h | 1 +
> hw/misc/aspeed_hace.c | 8 +++++++-
> 2 files changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/include/hw/misc/aspeed_hace.h b/include/hw/misc/aspeed_hace.h
> index 58fb66009a..db95f2fd4b 100644
> --- a/include/hw/misc/aspeed_hace.h
> +++ b/include/hw/misc/aspeed_hace.h
> @@ -53,6 +53,7 @@ struct AspeedHACEClass {
> uint32_t dest_hi_mask;
> uint32_t key_hi_mask;
> bool has_dma64;
> + uint64_t mem_size;
> };
>
> #endif /* ASPEED_HACE_H */
> diff --git a/hw/misc/aspeed_hace.c b/hw/misc/aspeed_hace.c
> index d4f653670e..53b3b390e3 100644
> --- a/hw/misc/aspeed_hace.c
> +++ b/hw/misc/aspeed_hace.c
> @@ -463,11 +463,12 @@ static void aspeed_hace_realize(DeviceState *dev, Error **errp)
> {
> AspeedHACEState *s = ASPEED_HACE(dev);
> SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
> + AspeedHACEClass *ahc = ASPEED_HACE_GET_CLASS(s);
>
> sysbus_init_irq(sbd, &s->irq);
>
> memory_region_init_io(&s->iomem, OBJECT(s), &aspeed_hace_ops, s,
> - TYPE_ASPEED_HACE, 0x1000);
> + TYPE_ASPEED_HACE, ahc->mem_size);
>
> if (!s->dram_mr) {
> error_setg(errp, TYPE_ASPEED_HACE ": 'dram' link not set");
> @@ -521,6 +522,7 @@ static void aspeed_ast2400_hace_class_init(ObjectClass *klass, void *data)
>
> dc->desc = "AST2400 Hash and Crypto Engine";
>
> + ahc->mem_size = 0x1000;
> ahc->src_mask = 0x0FFFFFFF;
> ahc->dest_mask = 0x0FFFFFF8;
> ahc->key_mask = 0x0FFFFFC0;
> @@ -540,6 +542,7 @@ static void aspeed_ast2500_hace_class_init(ObjectClass *klass, void *data)
>
> dc->desc = "AST2500 Hash and Crypto Engine";
>
> + ahc->mem_size = 0x1000;
> ahc->src_mask = 0x3fffffff;
> ahc->dest_mask = 0x3ffffff8;
> ahc->key_mask = 0x3FFFFFC0;
> @@ -559,6 +562,7 @@ static void aspeed_ast2600_hace_class_init(ObjectClass *klass, void *data)
>
> dc->desc = "AST2600 Hash and Crypto Engine";
>
> + ahc->mem_size = 0x10000;
> ahc->src_mask = 0x7FFFFFFF;
> ahc->dest_mask = 0x7FFFFFF8;
> ahc->key_mask = 0x7FFFFFF8;
> @@ -578,6 +582,7 @@ static void aspeed_ast1030_hace_class_init(ObjectClass *klass, void *data)
>
> dc->desc = "AST1030 Hash and Crypto Engine";
>
> + ahc->mem_size = 0x10000;
> ahc->src_mask = 0x7FFFFFFF;
> ahc->dest_mask = 0x7FFFFFF8;
> ahc->key_mask = 0x7FFFFFF8;
> @@ -597,6 +602,7 @@ static void aspeed_ast2700_hace_class_init(ObjectClass *klass, void *data)
>
> dc->desc = "AST2700 Hash and Crypto Engine";
>
> + ahc->mem_size = 0x100;
> ahc->src_mask = 0x7FFFFFFF;
> ahc->dest_mask = 0x7FFFFFF8;
> ahc->key_mask = 0x7FFFFFF8;