From 821e4599364bb7c78a4eb58eb72f88edb7cadc94 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Tue, 14 May 2024 21:11:32 +0200 Subject: [PATCH] [topgen] Improve support for multiple address spaces Individually generate C and Rust collateral for all address spaces Signed-off-by: Robert Schilling --- .../data/autogen/top_darjeeling.gen.hjson | 1 + hw/top_darjeeling/data/top_darjeeling.hjson | 2 +- .../rtl/autogen/top_darjeeling_soc_dbg_pkg.sv | 46 ++++ .../rtl/autogen/top_darjeeling_soc_mbx_pkg.sv | 106 +++++++++ hw/top_darjeeling/sw/autogen/chip/mod.rs | 4 + .../sw/autogen/chip/top_darjeeling_soc_dbg.rs | 70 ++++++ .../chip/top_darjeeling_soc_dbg_memory.rs | 62 +++++ .../sw/autogen/chip/top_darjeeling_soc_mbx.rs | 148 ++++++++++++ .../chip/top_darjeeling_soc_mbx_memory.rs | 140 ++++++++++++ .../sw/autogen/top_darjeeling_soc_dbg.c | 5 + .../sw/autogen/top_darjeeling_soc_dbg.h | 103 +++++++++ .../autogen/top_darjeeling_soc_dbg_memory.h | 92 ++++++++ .../sw/autogen/top_darjeeling_soc_mbx.c | 5 + .../sw/autogen/top_darjeeling_soc_mbx.h | 211 ++++++++++++++++++ .../autogen/top_darjeeling_soc_mbx_memory.h | 194 ++++++++++++++++ .../data/autogen/top_earlgrey.gen.hjson | 1 + hw/top_earlgrey/data/top_earlgrey.hjson | 2 +- .../data/top_englishbreakfast.hjson | 2 +- util/topgen.py | 208 +++++++++-------- util/topgen/c.py | 35 ++- util/topgen/c_test.py | 14 +- util/topgen/rust.py | 14 +- util/topgen/templates/toplevel.c.tpl | 4 +- util/topgen/templates/toplevel.h.tpl | 14 +- util/topgen/templates/toplevel.rs.tpl | 2 + util/topgen/templates/toplevel_memory.h.tpl | 12 +- util/topgen/templates/toplevel_mod.rs.tpl | 18 +- util/topgen/templates/toplevel_pkg.sv.tpl | 6 +- util/topgen/validate.py | 2 +- 29 files changed, 1403 insertions(+), 120 deletions(-) create mode 100644 hw/top_darjeeling/rtl/autogen/top_darjeeling_soc_dbg_pkg.sv create mode 100644 hw/top_darjeeling/rtl/autogen/top_darjeeling_soc_mbx_pkg.sv create mode 100644 hw/top_darjeeling/sw/autogen/chip/top_darjeeling_soc_dbg.rs create mode 100644 hw/top_darjeeling/sw/autogen/chip/top_darjeeling_soc_dbg_memory.rs create mode 100644 hw/top_darjeeling/sw/autogen/chip/top_darjeeling_soc_mbx.rs create mode 100644 hw/top_darjeeling/sw/autogen/chip/top_darjeeling_soc_mbx_memory.rs create mode 100644 hw/top_darjeeling/sw/autogen/top_darjeeling_soc_dbg.c create mode 100644 hw/top_darjeeling/sw/autogen/top_darjeeling_soc_dbg.h create mode 100644 hw/top_darjeeling/sw/autogen/top_darjeeling_soc_dbg_memory.h create mode 100644 hw/top_darjeeling/sw/autogen/top_darjeeling_soc_mbx.c create mode 100644 hw/top_darjeeling/sw/autogen/top_darjeeling_soc_mbx.h create mode 100644 hw/top_darjeeling/sw/autogen/top_darjeeling_soc_mbx_memory.h diff --git a/hw/top_darjeeling/data/autogen/top_darjeeling.gen.hjson b/hw/top_darjeeling/data/autogen/top_darjeeling.gen.hjson index 226faefaad6a0..8a5078ba57113 100644 --- a/hw/top_darjeeling/data/autogen/top_darjeeling.gen.hjson +++ b/hw/top_darjeeling/data/autogen/top_darjeeling.gen.hjson @@ -454,6 +454,7 @@ { name: hart desc: The main address space, shared between the CPU and DM + default: true } { name: soc_mbx diff --git a/hw/top_darjeeling/data/top_darjeeling.hjson b/hw/top_darjeeling/data/top_darjeeling.hjson index ec2c11cc675a8..de91449fb9bab 100644 --- a/hw/top_darjeeling/data/top_darjeeling.hjson +++ b/hw/top_darjeeling/data/top_darjeeling.hjson @@ -166,7 +166,7 @@ // all peripherals, though not every peripheral will be accessible to every // host in that address space--Access privileges are separate from addresses. addr_spaces: [ - { name: "hart", desc: "The main address space, shared between the CPU and DM"}, + { name: "hart", desc: "The main address space, shared between the CPU and DM", default: true}, { name: "soc_mbx", desc: "SoC address space for mailbox access"}, { name: "soc_dbg", desc: "SoC address space for debug module interfaces"}, ] diff --git a/hw/top_darjeeling/rtl/autogen/top_darjeeling_soc_dbg_pkg.sv b/hw/top_darjeeling/rtl/autogen/top_darjeeling_soc_dbg_pkg.sv new file mode 100644 index 0000000000000..2f2009bd07637 --- /dev/null +++ b/hw/top_darjeeling/rtl/autogen/top_darjeeling_soc_dbg_pkg.sv @@ -0,0 +1,46 @@ +// Copyright lowRISC contributors. +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 +// +// ------------------- W A R N I N G: A U T O - G E N E R A T E D C O D E !! -------------------// +// PLEASE DO NOT HAND-EDIT THIS FILE. IT HAS BEEN AUTO-GENERATED WITH THE FOLLOWING COMMAND: +// +// util/topgen.py -t hw/top_darjeeling/data/top_darjeeling.hjson \ +// -o hw/top_darjeeling/ \ +// --rnd_cnst_seed \ +// 1017106219537032642877583828875051302543807092889754935647094601236425074047 + +package top_darjeeling_soc_dbg_pkg; + /** + * Peripheral base address for dmi device on lc_ctrl in top darjeeling. + */ + parameter int unsigned TOP_DARJEELING_LC_CTRL_DMI_BASE_ADDR = 32'h20000; + + /** + * Peripheral size in bytes for dmi device on lc_ctrl in top darjeeling. + */ + parameter int unsigned TOP_DARJEELING_LC_CTRL_DMI_SIZE_BYTES = 32'h1000; + + /** + * Peripheral base address for dbg device on rv_dm in top darjeeling. + */ + parameter int unsigned TOP_DARJEELING_RV_DM_DBG_BASE_ADDR = 32'h0; + + /** + * Peripheral size in bytes for dbg device on rv_dm in top darjeeling. + */ + parameter int unsigned TOP_DARJEELING_RV_DM_DBG_SIZE_BYTES = 32'h200; + + /** + * Peripheral base address for soc device on mbx_jtag in top darjeeling. + */ + parameter int unsigned TOP_DARJEELING_MBX_JTAG_SOC_BASE_ADDR = 32'h1000; + + /** + * Peripheral size in bytes for soc device on mbx_jtag in top darjeeling. + */ + parameter int unsigned TOP_DARJEELING_MBX_JTAG_SOC_SIZE_BYTES = 32'h20; + + + +endpackage diff --git a/hw/top_darjeeling/rtl/autogen/top_darjeeling_soc_mbx_pkg.sv b/hw/top_darjeeling/rtl/autogen/top_darjeeling_soc_mbx_pkg.sv new file mode 100644 index 0000000000000..8bade2143fac5 --- /dev/null +++ b/hw/top_darjeeling/rtl/autogen/top_darjeeling_soc_mbx_pkg.sv @@ -0,0 +1,106 @@ +// Copyright lowRISC contributors. +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 +// +// ------------------- W A R N I N G: A U T O - G E N E R A T E D C O D E !! -------------------// +// PLEASE DO NOT HAND-EDIT THIS FILE. IT HAS BEEN AUTO-GENERATED WITH THE FOLLOWING COMMAND: +// +// util/topgen.py -t hw/top_darjeeling/data/top_darjeeling.hjson \ +// -o hw/top_darjeeling/ \ +// --rnd_cnst_seed \ +// 1017106219537032642877583828875051302543807092889754935647094601236425074047 + +package top_darjeeling_soc_mbx_pkg; + /** + * Peripheral base address for soc device on mbx0 in top darjeeling. + */ + parameter int unsigned TOP_DARJEELING_MBX0_SOC_BASE_ADDR = 32'h1465000; + + /** + * Peripheral size in bytes for soc device on mbx0 in top darjeeling. + */ + parameter int unsigned TOP_DARJEELING_MBX0_SOC_SIZE_BYTES = 32'h20; + + /** + * Peripheral base address for soc device on mbx1 in top darjeeling. + */ + parameter int unsigned TOP_DARJEELING_MBX1_SOC_BASE_ADDR = 32'h1465100; + + /** + * Peripheral size in bytes for soc device on mbx1 in top darjeeling. + */ + parameter int unsigned TOP_DARJEELING_MBX1_SOC_SIZE_BYTES = 32'h20; + + /** + * Peripheral base address for soc device on mbx2 in top darjeeling. + */ + parameter int unsigned TOP_DARJEELING_MBX2_SOC_BASE_ADDR = 32'h1465200; + + /** + * Peripheral size in bytes for soc device on mbx2 in top darjeeling. + */ + parameter int unsigned TOP_DARJEELING_MBX2_SOC_SIZE_BYTES = 32'h20; + + /** + * Peripheral base address for soc device on mbx3 in top darjeeling. + */ + parameter int unsigned TOP_DARJEELING_MBX3_SOC_BASE_ADDR = 32'h1465300; + + /** + * Peripheral size in bytes for soc device on mbx3 in top darjeeling. + */ + parameter int unsigned TOP_DARJEELING_MBX3_SOC_SIZE_BYTES = 32'h20; + + /** + * Peripheral base address for soc device on mbx4 in top darjeeling. + */ + parameter int unsigned TOP_DARJEELING_MBX4_SOC_BASE_ADDR = 32'h1465400; + + /** + * Peripheral size in bytes for soc device on mbx4 in top darjeeling. + */ + parameter int unsigned TOP_DARJEELING_MBX4_SOC_SIZE_BYTES = 32'h20; + + /** + * Peripheral base address for soc device on mbx5 in top darjeeling. + */ + parameter int unsigned TOP_DARJEELING_MBX5_SOC_BASE_ADDR = 32'h1465500; + + /** + * Peripheral size in bytes for soc device on mbx5 in top darjeeling. + */ + parameter int unsigned TOP_DARJEELING_MBX5_SOC_SIZE_BYTES = 32'h20; + + /** + * Peripheral base address for soc device on mbx6 in top darjeeling. + */ + parameter int unsigned TOP_DARJEELING_MBX6_SOC_BASE_ADDR = 32'h1465600; + + /** + * Peripheral size in bytes for soc device on mbx6 in top darjeeling. + */ + parameter int unsigned TOP_DARJEELING_MBX6_SOC_SIZE_BYTES = 32'h20; + + /** + * Peripheral base address for soc device on mbx_pcie0 in top darjeeling. + */ + parameter int unsigned TOP_DARJEELING_MBX_PCIE0_SOC_BASE_ADDR = 32'h1460100; + + /** + * Peripheral size in bytes for soc device on mbx_pcie0 in top darjeeling. + */ + parameter int unsigned TOP_DARJEELING_MBX_PCIE0_SOC_SIZE_BYTES = 32'h20; + + /** + * Peripheral base address for soc device on mbx_pcie1 in top darjeeling. + */ + parameter int unsigned TOP_DARJEELING_MBX_PCIE1_SOC_BASE_ADDR = 32'h1460200; + + /** + * Peripheral size in bytes for soc device on mbx_pcie1 in top darjeeling. + */ + parameter int unsigned TOP_DARJEELING_MBX_PCIE1_SOC_SIZE_BYTES = 32'h20; + + + +endpackage diff --git a/hw/top_darjeeling/sw/autogen/chip/mod.rs b/hw/top_darjeeling/sw/autogen/chip/mod.rs index 3964c8cd11647..eeb7ffb01f4bf 100644 --- a/hw/top_darjeeling/sw/autogen/chip/mod.rs +++ b/hw/top_darjeeling/sw/autogen/chip/mod.rs @@ -4,3 +4,7 @@ pub mod top_darjeeling; pub mod top_darjeeling_memory; +pub mod top_darjeeling_soc_dbg; +pub mod top_darjeeling_soc_dbg_memory; +pub mod top_darjeeling_soc_mbx; +pub mod top_darjeeling_soc_mbx_memory; diff --git a/hw/top_darjeeling/sw/autogen/chip/top_darjeeling_soc_dbg.rs b/hw/top_darjeeling/sw/autogen/chip/top_darjeeling_soc_dbg.rs new file mode 100644 index 0000000000000..645a4cb53cafa --- /dev/null +++ b/hw/top_darjeeling/sw/autogen/chip/top_darjeeling_soc_dbg.rs @@ -0,0 +1,70 @@ +// Copyright lowRISC contributors. +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 + +// This file was generated automatically. +// Please do not modify content of this file directly. +// File generated by using template: "toplevel.rs.tpl" +// To regenerate this file follow OpenTitan topgen documentations. + +#![allow(dead_code)] + +//! This file contains enums and consts for use within the Rust codebase. +//! +//! These definitions are for information that depends on the top-specific chip +//! configuration, which includes: +//! - Device Memory Information (for Peripherals and Memory) +//! - PLIC Interrupt ID Names and Source Mappings +//! - Alert ID Names and Source Mappings +//! - Pinmux Pin/Select Names +//! - Power Manager Wakeups + +use core::convert::TryFrom; + +/// Peripheral base address for dmi device on lc_ctrl in top darjeeling. +/// +/// This should be used with #mmio_region_from_addr to access the memory-mapped +/// registers associated with the peripheral (usually via a DIF). +pub const TOP_DARJEELING_LC_CTRL_DMI_BASE_ADDR: usize = 0x20000; + +/// Peripheral size for dmi device on lc_ctrl in top darjeeling. +/// +/// This is the size (in bytes) of the peripheral's reserved memory area. All +/// memory-mapped registers associated with this peripheral should have an +/// address between #TOP_DARJEELING_LC_CTRL_DMI_BASE_ADDR and +/// `TOP_DARJEELING_LC_CTRL_DMI_BASE_ADDR + TOP_DARJEELING_LC_CTRL_DMI_SIZE_BYTES`. +pub const TOP_DARJEELING_LC_CTRL_DMI_SIZE_BYTES: usize = 0x1000; +/// Peripheral base address for dbg device on rv_dm in top darjeeling. +/// +/// This should be used with #mmio_region_from_addr to access the memory-mapped +/// registers associated with the peripheral (usually via a DIF). +pub const TOP_DARJEELING_RV_DM_DBG_BASE_ADDR: usize = 0x0; + +/// Peripheral size for dbg device on rv_dm in top darjeeling. +/// +/// This is the size (in bytes) of the peripheral's reserved memory area. All +/// memory-mapped registers associated with this peripheral should have an +/// address between #TOP_DARJEELING_RV_DM_DBG_BASE_ADDR and +/// `TOP_DARJEELING_RV_DM_DBG_BASE_ADDR + TOP_DARJEELING_RV_DM_DBG_SIZE_BYTES`. +pub const TOP_DARJEELING_RV_DM_DBG_SIZE_BYTES: usize = 0x200; +/// Peripheral base address for soc device on mbx_jtag in top darjeeling. +/// +/// This should be used with #mmio_region_from_addr to access the memory-mapped +/// registers associated with the peripheral (usually via a DIF). +pub const TOP_DARJEELING_MBX_JTAG_SOC_BASE_ADDR: usize = 0x1000; + +/// Peripheral size for soc device on mbx_jtag in top darjeeling. +/// +/// This is the size (in bytes) of the peripheral's reserved memory area. All +/// memory-mapped registers associated with this peripheral should have an +/// address between #TOP_DARJEELING_MBX_JTAG_SOC_BASE_ADDR and +/// `TOP_DARJEELING_MBX_JTAG_SOC_BASE_ADDR + TOP_DARJEELING_MBX_JTAG_SOC_SIZE_BYTES`. +pub const TOP_DARJEELING_MBX_JTAG_SOC_SIZE_BYTES: usize = 0x20; + +/// MMIO Region +/// +/// MMIO region excludes any memory that is separate from the module +/// configuration space, i.e. ROM, main SRAM, and flash are excluded but +/// retention SRAM, spi_device memory, or usbdev memory are included. +pub const TOP_DARJEELING_MMIO_BASE_ADDR: usize = 0x1000; +pub const TOP_DARJEELING_MMIO_SIZE_BYTES: usize = 0x20000; diff --git a/hw/top_darjeeling/sw/autogen/chip/top_darjeeling_soc_dbg_memory.rs b/hw/top_darjeeling/sw/autogen/chip/top_darjeeling_soc_dbg_memory.rs new file mode 100644 index 0000000000000..9416878f7a516 --- /dev/null +++ b/hw/top_darjeeling/sw/autogen/chip/top_darjeeling_soc_dbg_memory.rs @@ -0,0 +1,62 @@ +// Copyright lowRISC contributors. +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 + +// This file was generated automatically. +// Please do not modify content of this file directly. +// File generated by using template: "toplevel_memory.rs.tpl" +// To regenerate this file follow OpenTitan topgen documentations. + +#![allow(dead_code)] + +//! Rust Top-Specific Definitions. +//! +//! This file contains const definitions for use within Rust code. + +/// Peripheral base address for dmi device on lc_ctrl in top darjeeling. +/// +/// This should be used with #mmio_region_from_addr to access the memory-mapped +/// registers associated with the peripheral (usually via a DIF). +pub const TOP_DARJEELING_LC_CTRL_DMI_BASE_ADDR: usize = 0x20000; + +/// Peripheral size for dmi device on lc_ctrl in top darjeeling. +/// +/// This is the size (in bytes) of the peripheral's reserved memory area. All +/// memory-mapped registers associated with this peripheral should have an +/// address between #TOP_DARJEELING_LC_CTRL_DMI_BASE_ADDR and +/// `TOP_DARJEELING_LC_CTRL_DMI_BASE_ADDR + TOP_DARJEELING_LC_CTRL_DMI_SIZE_BYTES`. +pub const TOP_DARJEELING_LC_CTRL_DMI_SIZE_BYTES: usize = 0x1000; +/// Peripheral base address for dbg device on rv_dm in top darjeeling. +/// +/// This should be used with #mmio_region_from_addr to access the memory-mapped +/// registers associated with the peripheral (usually via a DIF). +pub const TOP_DARJEELING_RV_DM_DBG_BASE_ADDR: usize = 0x0; + +/// Peripheral size for dbg device on rv_dm in top darjeeling. +/// +/// This is the size (in bytes) of the peripheral's reserved memory area. All +/// memory-mapped registers associated with this peripheral should have an +/// address between #TOP_DARJEELING_RV_DM_DBG_BASE_ADDR and +/// `TOP_DARJEELING_RV_DM_DBG_BASE_ADDR + TOP_DARJEELING_RV_DM_DBG_SIZE_BYTES`. +pub const TOP_DARJEELING_RV_DM_DBG_SIZE_BYTES: usize = 0x200; +/// Peripheral base address for soc device on mbx_jtag in top darjeeling. +/// +/// This should be used with #mmio_region_from_addr to access the memory-mapped +/// registers associated with the peripheral (usually via a DIF). +pub const TOP_DARJEELING_MBX_JTAG_SOC_BASE_ADDR: usize = 0x1000; + +/// Peripheral size for soc device on mbx_jtag in top darjeeling. +/// +/// This is the size (in bytes) of the peripheral's reserved memory area. All +/// memory-mapped registers associated with this peripheral should have an +/// address between #TOP_DARJEELING_MBX_JTAG_SOC_BASE_ADDR and +/// `TOP_DARJEELING_MBX_JTAG_SOC_BASE_ADDR + TOP_DARJEELING_MBX_JTAG_SOC_SIZE_BYTES`. +pub const TOP_DARJEELING_MBX_JTAG_SOC_SIZE_BYTES: usize = 0x20; + +/// MMIO Region +/// +/// MMIO region excludes any memory that is separate from the module +/// configuration space, i.e. ROM, main SRAM, and flash are excluded but +/// retention SRAM, spi_device memory, or usbdev memory are included. +pub const TOP_DARJEELING_MMIO_BASE_ADDR: usize = 0x1000; +pub const TOP_DARJEELING_MMIO_SIZE_BYTES: usize = 0x20000; diff --git a/hw/top_darjeeling/sw/autogen/chip/top_darjeeling_soc_mbx.rs b/hw/top_darjeeling/sw/autogen/chip/top_darjeeling_soc_mbx.rs new file mode 100644 index 0000000000000..a8c7d4b1e9437 --- /dev/null +++ b/hw/top_darjeeling/sw/autogen/chip/top_darjeeling_soc_mbx.rs @@ -0,0 +1,148 @@ +// Copyright lowRISC contributors. +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 + +// This file was generated automatically. +// Please do not modify content of this file directly. +// File generated by using template: "toplevel.rs.tpl" +// To regenerate this file follow OpenTitan topgen documentations. + +#![allow(dead_code)] + +//! This file contains enums and consts for use within the Rust codebase. +//! +//! These definitions are for information that depends on the top-specific chip +//! configuration, which includes: +//! - Device Memory Information (for Peripherals and Memory) +//! - PLIC Interrupt ID Names and Source Mappings +//! - Alert ID Names and Source Mappings +//! - Pinmux Pin/Select Names +//! - Power Manager Wakeups + +use core::convert::TryFrom; + +/// Peripheral base address for soc device on mbx0 in top darjeeling. +/// +/// This should be used with #mmio_region_from_addr to access the memory-mapped +/// registers associated with the peripheral (usually via a DIF). +pub const TOP_DARJEELING_MBX0_SOC_BASE_ADDR: usize = 0x1465000; + +/// Peripheral size for soc device on mbx0 in top darjeeling. +/// +/// This is the size (in bytes) of the peripheral's reserved memory area. All +/// memory-mapped registers associated with this peripheral should have an +/// address between #TOP_DARJEELING_MBX0_SOC_BASE_ADDR and +/// `TOP_DARJEELING_MBX0_SOC_BASE_ADDR + TOP_DARJEELING_MBX0_SOC_SIZE_BYTES`. +pub const TOP_DARJEELING_MBX0_SOC_SIZE_BYTES: usize = 0x20; +/// Peripheral base address for soc device on mbx1 in top darjeeling. +/// +/// This should be used with #mmio_region_from_addr to access the memory-mapped +/// registers associated with the peripheral (usually via a DIF). +pub const TOP_DARJEELING_MBX1_SOC_BASE_ADDR: usize = 0x1465100; + +/// Peripheral size for soc device on mbx1 in top darjeeling. +/// +/// This is the size (in bytes) of the peripheral's reserved memory area. All +/// memory-mapped registers associated with this peripheral should have an +/// address between #TOP_DARJEELING_MBX1_SOC_BASE_ADDR and +/// `TOP_DARJEELING_MBX1_SOC_BASE_ADDR + TOP_DARJEELING_MBX1_SOC_SIZE_BYTES`. +pub const TOP_DARJEELING_MBX1_SOC_SIZE_BYTES: usize = 0x20; +/// Peripheral base address for soc device on mbx2 in top darjeeling. +/// +/// This should be used with #mmio_region_from_addr to access the memory-mapped +/// registers associated with the peripheral (usually via a DIF). +pub const TOP_DARJEELING_MBX2_SOC_BASE_ADDR: usize = 0x1465200; + +/// Peripheral size for soc device on mbx2 in top darjeeling. +/// +/// This is the size (in bytes) of the peripheral's reserved memory area. All +/// memory-mapped registers associated with this peripheral should have an +/// address between #TOP_DARJEELING_MBX2_SOC_BASE_ADDR and +/// `TOP_DARJEELING_MBX2_SOC_BASE_ADDR + TOP_DARJEELING_MBX2_SOC_SIZE_BYTES`. +pub const TOP_DARJEELING_MBX2_SOC_SIZE_BYTES: usize = 0x20; +/// Peripheral base address for soc device on mbx3 in top darjeeling. +/// +/// This should be used with #mmio_region_from_addr to access the memory-mapped +/// registers associated with the peripheral (usually via a DIF). +pub const TOP_DARJEELING_MBX3_SOC_BASE_ADDR: usize = 0x1465300; + +/// Peripheral size for soc device on mbx3 in top darjeeling. +/// +/// This is the size (in bytes) of the peripheral's reserved memory area. All +/// memory-mapped registers associated with this peripheral should have an +/// address between #TOP_DARJEELING_MBX3_SOC_BASE_ADDR and +/// `TOP_DARJEELING_MBX3_SOC_BASE_ADDR + TOP_DARJEELING_MBX3_SOC_SIZE_BYTES`. +pub const TOP_DARJEELING_MBX3_SOC_SIZE_BYTES: usize = 0x20; +/// Peripheral base address for soc device on mbx4 in top darjeeling. +/// +/// This should be used with #mmio_region_from_addr to access the memory-mapped +/// registers associated with the peripheral (usually via a DIF). +pub const TOP_DARJEELING_MBX4_SOC_BASE_ADDR: usize = 0x1465400; + +/// Peripheral size for soc device on mbx4 in top darjeeling. +/// +/// This is the size (in bytes) of the peripheral's reserved memory area. All +/// memory-mapped registers associated with this peripheral should have an +/// address between #TOP_DARJEELING_MBX4_SOC_BASE_ADDR and +/// `TOP_DARJEELING_MBX4_SOC_BASE_ADDR + TOP_DARJEELING_MBX4_SOC_SIZE_BYTES`. +pub const TOP_DARJEELING_MBX4_SOC_SIZE_BYTES: usize = 0x20; +/// Peripheral base address for soc device on mbx5 in top darjeeling. +/// +/// This should be used with #mmio_region_from_addr to access the memory-mapped +/// registers associated with the peripheral (usually via a DIF). +pub const TOP_DARJEELING_MBX5_SOC_BASE_ADDR: usize = 0x1465500; + +/// Peripheral size for soc device on mbx5 in top darjeeling. +/// +/// This is the size (in bytes) of the peripheral's reserved memory area. All +/// memory-mapped registers associated with this peripheral should have an +/// address between #TOP_DARJEELING_MBX5_SOC_BASE_ADDR and +/// `TOP_DARJEELING_MBX5_SOC_BASE_ADDR + TOP_DARJEELING_MBX5_SOC_SIZE_BYTES`. +pub const TOP_DARJEELING_MBX5_SOC_SIZE_BYTES: usize = 0x20; +/// Peripheral base address for soc device on mbx6 in top darjeeling. +/// +/// This should be used with #mmio_region_from_addr to access the memory-mapped +/// registers associated with the peripheral (usually via a DIF). +pub const TOP_DARJEELING_MBX6_SOC_BASE_ADDR: usize = 0x1465600; + +/// Peripheral size for soc device on mbx6 in top darjeeling. +/// +/// This is the size (in bytes) of the peripheral's reserved memory area. All +/// memory-mapped registers associated with this peripheral should have an +/// address between #TOP_DARJEELING_MBX6_SOC_BASE_ADDR and +/// `TOP_DARJEELING_MBX6_SOC_BASE_ADDR + TOP_DARJEELING_MBX6_SOC_SIZE_BYTES`. +pub const TOP_DARJEELING_MBX6_SOC_SIZE_BYTES: usize = 0x20; +/// Peripheral base address for soc device on mbx_pcie0 in top darjeeling. +/// +/// This should be used with #mmio_region_from_addr to access the memory-mapped +/// registers associated with the peripheral (usually via a DIF). +pub const TOP_DARJEELING_MBX_PCIE0_SOC_BASE_ADDR: usize = 0x1460100; + +/// Peripheral size for soc device on mbx_pcie0 in top darjeeling. +/// +/// This is the size (in bytes) of the peripheral's reserved memory area. All +/// memory-mapped registers associated with this peripheral should have an +/// address between #TOP_DARJEELING_MBX_PCIE0_SOC_BASE_ADDR and +/// `TOP_DARJEELING_MBX_PCIE0_SOC_BASE_ADDR + TOP_DARJEELING_MBX_PCIE0_SOC_SIZE_BYTES`. +pub const TOP_DARJEELING_MBX_PCIE0_SOC_SIZE_BYTES: usize = 0x20; +/// Peripheral base address for soc device on mbx_pcie1 in top darjeeling. +/// +/// This should be used with #mmio_region_from_addr to access the memory-mapped +/// registers associated with the peripheral (usually via a DIF). +pub const TOP_DARJEELING_MBX_PCIE1_SOC_BASE_ADDR: usize = 0x1460200; + +/// Peripheral size for soc device on mbx_pcie1 in top darjeeling. +/// +/// This is the size (in bytes) of the peripheral's reserved memory area. All +/// memory-mapped registers associated with this peripheral should have an +/// address between #TOP_DARJEELING_MBX_PCIE1_SOC_BASE_ADDR and +/// `TOP_DARJEELING_MBX_PCIE1_SOC_BASE_ADDR + TOP_DARJEELING_MBX_PCIE1_SOC_SIZE_BYTES`. +pub const TOP_DARJEELING_MBX_PCIE1_SOC_SIZE_BYTES: usize = 0x20; + +/// MMIO Region +/// +/// MMIO region excludes any memory that is separate from the module +/// configuration space, i.e. ROM, main SRAM, and flash are excluded but +/// retention SRAM, spi_device memory, or usbdev memory are included. +pub const TOP_DARJEELING_MMIO_BASE_ADDR: usize = 0x1460100; +pub const TOP_DARJEELING_MMIO_SIZE_BYTES: usize = 0x5520; diff --git a/hw/top_darjeeling/sw/autogen/chip/top_darjeeling_soc_mbx_memory.rs b/hw/top_darjeeling/sw/autogen/chip/top_darjeeling_soc_mbx_memory.rs new file mode 100644 index 0000000000000..0cb35d53f7358 --- /dev/null +++ b/hw/top_darjeeling/sw/autogen/chip/top_darjeeling_soc_mbx_memory.rs @@ -0,0 +1,140 @@ +// Copyright lowRISC contributors. +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 + +// This file was generated automatically. +// Please do not modify content of this file directly. +// File generated by using template: "toplevel_memory.rs.tpl" +// To regenerate this file follow OpenTitan topgen documentations. + +#![allow(dead_code)] + +//! Rust Top-Specific Definitions. +//! +//! This file contains const definitions for use within Rust code. + +/// Peripheral base address for soc device on mbx0 in top darjeeling. +/// +/// This should be used with #mmio_region_from_addr to access the memory-mapped +/// registers associated with the peripheral (usually via a DIF). +pub const TOP_DARJEELING_MBX0_SOC_BASE_ADDR: usize = 0x1465000; + +/// Peripheral size for soc device on mbx0 in top darjeeling. +/// +/// This is the size (in bytes) of the peripheral's reserved memory area. All +/// memory-mapped registers associated with this peripheral should have an +/// address between #TOP_DARJEELING_MBX0_SOC_BASE_ADDR and +/// `TOP_DARJEELING_MBX0_SOC_BASE_ADDR + TOP_DARJEELING_MBX0_SOC_SIZE_BYTES`. +pub const TOP_DARJEELING_MBX0_SOC_SIZE_BYTES: usize = 0x20; +/// Peripheral base address for soc device on mbx1 in top darjeeling. +/// +/// This should be used with #mmio_region_from_addr to access the memory-mapped +/// registers associated with the peripheral (usually via a DIF). +pub const TOP_DARJEELING_MBX1_SOC_BASE_ADDR: usize = 0x1465100; + +/// Peripheral size for soc device on mbx1 in top darjeeling. +/// +/// This is the size (in bytes) of the peripheral's reserved memory area. All +/// memory-mapped registers associated with this peripheral should have an +/// address between #TOP_DARJEELING_MBX1_SOC_BASE_ADDR and +/// `TOP_DARJEELING_MBX1_SOC_BASE_ADDR + TOP_DARJEELING_MBX1_SOC_SIZE_BYTES`. +pub const TOP_DARJEELING_MBX1_SOC_SIZE_BYTES: usize = 0x20; +/// Peripheral base address for soc device on mbx2 in top darjeeling. +/// +/// This should be used with #mmio_region_from_addr to access the memory-mapped +/// registers associated with the peripheral (usually via a DIF). +pub const TOP_DARJEELING_MBX2_SOC_BASE_ADDR: usize = 0x1465200; + +/// Peripheral size for soc device on mbx2 in top darjeeling. +/// +/// This is the size (in bytes) of the peripheral's reserved memory area. All +/// memory-mapped registers associated with this peripheral should have an +/// address between #TOP_DARJEELING_MBX2_SOC_BASE_ADDR and +/// `TOP_DARJEELING_MBX2_SOC_BASE_ADDR + TOP_DARJEELING_MBX2_SOC_SIZE_BYTES`. +pub const TOP_DARJEELING_MBX2_SOC_SIZE_BYTES: usize = 0x20; +/// Peripheral base address for soc device on mbx3 in top darjeeling. +/// +/// This should be used with #mmio_region_from_addr to access the memory-mapped +/// registers associated with the peripheral (usually via a DIF). +pub const TOP_DARJEELING_MBX3_SOC_BASE_ADDR: usize = 0x1465300; + +/// Peripheral size for soc device on mbx3 in top darjeeling. +/// +/// This is the size (in bytes) of the peripheral's reserved memory area. All +/// memory-mapped registers associated with this peripheral should have an +/// address between #TOP_DARJEELING_MBX3_SOC_BASE_ADDR and +/// `TOP_DARJEELING_MBX3_SOC_BASE_ADDR + TOP_DARJEELING_MBX3_SOC_SIZE_BYTES`. +pub const TOP_DARJEELING_MBX3_SOC_SIZE_BYTES: usize = 0x20; +/// Peripheral base address for soc device on mbx4 in top darjeeling. +/// +/// This should be used with #mmio_region_from_addr to access the memory-mapped +/// registers associated with the peripheral (usually via a DIF). +pub const TOP_DARJEELING_MBX4_SOC_BASE_ADDR: usize = 0x1465400; + +/// Peripheral size for soc device on mbx4 in top darjeeling. +/// +/// This is the size (in bytes) of the peripheral's reserved memory area. All +/// memory-mapped registers associated with this peripheral should have an +/// address between #TOP_DARJEELING_MBX4_SOC_BASE_ADDR and +/// `TOP_DARJEELING_MBX4_SOC_BASE_ADDR + TOP_DARJEELING_MBX4_SOC_SIZE_BYTES`. +pub const TOP_DARJEELING_MBX4_SOC_SIZE_BYTES: usize = 0x20; +/// Peripheral base address for soc device on mbx5 in top darjeeling. +/// +/// This should be used with #mmio_region_from_addr to access the memory-mapped +/// registers associated with the peripheral (usually via a DIF). +pub const TOP_DARJEELING_MBX5_SOC_BASE_ADDR: usize = 0x1465500; + +/// Peripheral size for soc device on mbx5 in top darjeeling. +/// +/// This is the size (in bytes) of the peripheral's reserved memory area. All +/// memory-mapped registers associated with this peripheral should have an +/// address between #TOP_DARJEELING_MBX5_SOC_BASE_ADDR and +/// `TOP_DARJEELING_MBX5_SOC_BASE_ADDR + TOP_DARJEELING_MBX5_SOC_SIZE_BYTES`. +pub const TOP_DARJEELING_MBX5_SOC_SIZE_BYTES: usize = 0x20; +/// Peripheral base address for soc device on mbx6 in top darjeeling. +/// +/// This should be used with #mmio_region_from_addr to access the memory-mapped +/// registers associated with the peripheral (usually via a DIF). +pub const TOP_DARJEELING_MBX6_SOC_BASE_ADDR: usize = 0x1465600; + +/// Peripheral size for soc device on mbx6 in top darjeeling. +/// +/// This is the size (in bytes) of the peripheral's reserved memory area. All +/// memory-mapped registers associated with this peripheral should have an +/// address between #TOP_DARJEELING_MBX6_SOC_BASE_ADDR and +/// `TOP_DARJEELING_MBX6_SOC_BASE_ADDR + TOP_DARJEELING_MBX6_SOC_SIZE_BYTES`. +pub const TOP_DARJEELING_MBX6_SOC_SIZE_BYTES: usize = 0x20; +/// Peripheral base address for soc device on mbx_pcie0 in top darjeeling. +/// +/// This should be used with #mmio_region_from_addr to access the memory-mapped +/// registers associated with the peripheral (usually via a DIF). +pub const TOP_DARJEELING_MBX_PCIE0_SOC_BASE_ADDR: usize = 0x1460100; + +/// Peripheral size for soc device on mbx_pcie0 in top darjeeling. +/// +/// This is the size (in bytes) of the peripheral's reserved memory area. All +/// memory-mapped registers associated with this peripheral should have an +/// address between #TOP_DARJEELING_MBX_PCIE0_SOC_BASE_ADDR and +/// `TOP_DARJEELING_MBX_PCIE0_SOC_BASE_ADDR + TOP_DARJEELING_MBX_PCIE0_SOC_SIZE_BYTES`. +pub const TOP_DARJEELING_MBX_PCIE0_SOC_SIZE_BYTES: usize = 0x20; +/// Peripheral base address for soc device on mbx_pcie1 in top darjeeling. +/// +/// This should be used with #mmio_region_from_addr to access the memory-mapped +/// registers associated with the peripheral (usually via a DIF). +pub const TOP_DARJEELING_MBX_PCIE1_SOC_BASE_ADDR: usize = 0x1460200; + +/// Peripheral size for soc device on mbx_pcie1 in top darjeeling. +/// +/// This is the size (in bytes) of the peripheral's reserved memory area. All +/// memory-mapped registers associated with this peripheral should have an +/// address between #TOP_DARJEELING_MBX_PCIE1_SOC_BASE_ADDR and +/// `TOP_DARJEELING_MBX_PCIE1_SOC_BASE_ADDR + TOP_DARJEELING_MBX_PCIE1_SOC_SIZE_BYTES`. +pub const TOP_DARJEELING_MBX_PCIE1_SOC_SIZE_BYTES: usize = 0x20; + +/// MMIO Region +/// +/// MMIO region excludes any memory that is separate from the module +/// configuration space, i.e. ROM, main SRAM, and flash are excluded but +/// retention SRAM, spi_device memory, or usbdev memory are included. +pub const TOP_DARJEELING_MMIO_BASE_ADDR: usize = 0x1460100; +pub const TOP_DARJEELING_MMIO_SIZE_BYTES: usize = 0x5520; diff --git a/hw/top_darjeeling/sw/autogen/top_darjeeling_soc_dbg.c b/hw/top_darjeeling/sw/autogen/top_darjeeling_soc_dbg.c new file mode 100644 index 0000000000000..d3845222613b7 --- /dev/null +++ b/hw/top_darjeeling/sw/autogen/top_darjeeling_soc_dbg.c @@ -0,0 +1,5 @@ +// Copyright lowRISC contributors. +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 + +#include "hw/top_darjeeling/sw/autogen/top_darjeeling_soc_dbg.h" diff --git a/hw/top_darjeeling/sw/autogen/top_darjeeling_soc_dbg.h b/hw/top_darjeeling/sw/autogen/top_darjeeling_soc_dbg.h new file mode 100644 index 0000000000000..d1b4159b51a4e --- /dev/null +++ b/hw/top_darjeeling/sw/autogen/top_darjeeling_soc_dbg.h @@ -0,0 +1,103 @@ +// Copyright lowRISC contributors. +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 + +#ifndef OPENTITAN_HW_TOP_DARJEELING_SW_AUTOGEN_TOP_DARJEELING_SOC_DBG_H_ +#define OPENTITAN_HW_TOP_DARJEELING_SW_AUTOGEN_TOP_DARJEELING_SOC_DBG_H_ + +#include "top_darjeeling_flash_ctrl_dummy.h" +#include "top_darjeeling_keymgr_dummy.h" + +/** + * @file + * @brief Top-specific Definitions + * + * This file contains preprocessor and type definitions for use within the + * device C/C++ codebase. + * + * These definitions are for information that depends on the top-specific chip + * configuration, which includes: + * - Device Memory Information (for Peripherals and Memory) + * - PLIC Interrupt ID Names and Source Mappings + * - Alert ID Names and Source Mappings + * - Pinmux Pin/Select Names + * - Power Manager Wakeups + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Peripheral base address for dmi device on lc_ctrl in top darjeeling. + * + * This should be used with #mmio_region_from_addr to access the memory-mapped + * registers associated with the peripheral (usually via a DIF). + */ +#define TOP_DARJEELING_LC_CTRL_DMI_BASE_ADDR 0x20000u + +/** + * Peripheral size for dmi device on lc_ctrl in top darjeeling. + * + * This is the size (in bytes) of the peripheral's reserved memory area. All + * memory-mapped registers associated with this peripheral should have an + * address between #TOP_DARJEELING_LC_CTRL_DMI_BASE_ADDR and + * `TOP_DARJEELING_LC_CTRL_DMI_BASE_ADDR + TOP_DARJEELING_LC_CTRL_DMI_SIZE_BYTES`. + */ +#define TOP_DARJEELING_LC_CTRL_DMI_SIZE_BYTES 0x1000u + +/** + * Peripheral base address for dbg device on rv_dm in top darjeeling. + * + * This should be used with #mmio_region_from_addr to access the memory-mapped + * registers associated with the peripheral (usually via a DIF). + */ +#define TOP_DARJEELING_RV_DM_DBG_BASE_ADDR 0x0u + +/** + * Peripheral size for dbg device on rv_dm in top darjeeling. + * + * This is the size (in bytes) of the peripheral's reserved memory area. All + * memory-mapped registers associated with this peripheral should have an + * address between #TOP_DARJEELING_RV_DM_DBG_BASE_ADDR and + * `TOP_DARJEELING_RV_DM_DBG_BASE_ADDR + TOP_DARJEELING_RV_DM_DBG_SIZE_BYTES`. + */ +#define TOP_DARJEELING_RV_DM_DBG_SIZE_BYTES 0x200u + +/** + * Peripheral base address for soc device on mbx_jtag in top darjeeling. + * + * This should be used with #mmio_region_from_addr to access the memory-mapped + * registers associated with the peripheral (usually via a DIF). + */ +#define TOP_DARJEELING_MBX_JTAG_SOC_BASE_ADDR 0x1000u + +/** + * Peripheral size for soc device on mbx_jtag in top darjeeling. + * + * This is the size (in bytes) of the peripheral's reserved memory area. All + * memory-mapped registers associated with this peripheral should have an + * address between #TOP_DARJEELING_MBX_JTAG_SOC_BASE_ADDR and + * `TOP_DARJEELING_MBX_JTAG_SOC_BASE_ADDR + TOP_DARJEELING_MBX_JTAG_SOC_SIZE_BYTES`. + */ +#define TOP_DARJEELING_MBX_JTAG_SOC_SIZE_BYTES 0x20u + + + + +/** + * MMIO Region + * + * MMIO region excludes any memory that is separate from the module + * configuration space, i.e. ROM, main SRAM, and flash are excluded but + * retention SRAM, spi_device memory, or usbdev memory are included. + */ +#define TOP_DARJEELING_MMIO_BASE_ADDR 0x1000u +#define TOP_DARJEELING_MMIO_SIZE_BYTES 0x20000u + +// Header Extern Guard +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // OPENTITAN_HW_TOP_DARJEELING_SW_AUTOGEN_TOP_DARJEELING_SOC_DBG_H_ diff --git a/hw/top_darjeeling/sw/autogen/top_darjeeling_soc_dbg_memory.h b/hw/top_darjeeling/sw/autogen/top_darjeeling_soc_dbg_memory.h new file mode 100644 index 0000000000000..7dd2a46e006e0 --- /dev/null +++ b/hw/top_darjeeling/sw/autogen/top_darjeeling_soc_dbg_memory.h @@ -0,0 +1,92 @@ +// Copyright lowRISC contributors. +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 + +#ifndef OPENTITAN_HW_TOP_DARJEELING_SW_AUTOGEN_TOP_DARJEELING_SOC_DBG_MEMORY_H_ +#define OPENTITAN_HW_TOP_DARJEELING_SW_AUTOGEN_TOP_DARJEELING_SOC_DBG_MEMORY_H_ + +#include "top_darjeeling_flash_ctrl_dummy.h" +#include "top_darjeeling_keymgr_dummy.h" + +/** + * @file + * @brief Assembler-only Top-Specific Definitions. + * + * This file contains preprocessor definitions for use within assembly code. + * + * These are not shared with C/C++ code because these are only allowed to be + * preprocessor definitions, no data or type declarations are allowed. The + * assembler is also stricter about literals (not allowing suffixes for + * signed/unsigned which are sensible to use for unsigned values in C/C++). + */ + +// Include guard for assembler +#ifdef __ASSEMBLER__ + + + +/** + * Peripheral base address for dmi device on lc_ctrl in top darjeeling. + * + * This should be used with #mmio_region_from_addr to access the memory-mapped + * registers associated with the peripheral (usually via a DIF). + */ +#define TOP_DARJEELING_LC_CTRL_DMI_BASE_ADDR 0x20000 + +/** + * Peripheral size for dmi device on lc_ctrl in top darjeeling. + * + * This is the size (in bytes) of the peripheral's reserved memory area. All + * memory-mapped registers associated with this peripheral should have an + * address between #TOP_DARJEELING_LC_CTRL_DMI_BASE_ADDR and + * `TOP_DARJEELING_LC_CTRL_DMI_BASE_ADDR + TOP_DARJEELING_LC_CTRL_DMI_SIZE_BYTES`. + */ +#define TOP_DARJEELING_LC_CTRL_DMI_SIZE_BYTES 0x1000 +/** + * Peripheral base address for dbg device on rv_dm in top darjeeling. + * + * This should be used with #mmio_region_from_addr to access the memory-mapped + * registers associated with the peripheral (usually via a DIF). + */ +#define TOP_DARJEELING_RV_DM_DBG_BASE_ADDR 0x0 + +/** + * Peripheral size for dbg device on rv_dm in top darjeeling. + * + * This is the size (in bytes) of the peripheral's reserved memory area. All + * memory-mapped registers associated with this peripheral should have an + * address between #TOP_DARJEELING_RV_DM_DBG_BASE_ADDR and + * `TOP_DARJEELING_RV_DM_DBG_BASE_ADDR + TOP_DARJEELING_RV_DM_DBG_SIZE_BYTES`. + */ +#define TOP_DARJEELING_RV_DM_DBG_SIZE_BYTES 0x200 +/** + * Peripheral base address for soc device on mbx_jtag in top darjeeling. + * + * This should be used with #mmio_region_from_addr to access the memory-mapped + * registers associated with the peripheral (usually via a DIF). + */ +#define TOP_DARJEELING_MBX_JTAG_SOC_BASE_ADDR 0x1000 + +/** + * Peripheral size for soc device on mbx_jtag in top darjeeling. + * + * This is the size (in bytes) of the peripheral's reserved memory area. All + * memory-mapped registers associated with this peripheral should have an + * address between #TOP_DARJEELING_MBX_JTAG_SOC_BASE_ADDR and + * `TOP_DARJEELING_MBX_JTAG_SOC_BASE_ADDR + TOP_DARJEELING_MBX_JTAG_SOC_SIZE_BYTES`. + */ +#define TOP_DARJEELING_MBX_JTAG_SOC_SIZE_BYTES 0x20 + +/** + * MMIO Region + * + * MMIO region excludes any memory that is separate from the module + * configuration space, i.e. ROM, main SRAM, and flash are excluded but + * retention SRAM, spi_device memory, or usbdev memory are included. + */ +#define TOP_DARJEELING_MMIO_BASE_ADDR 0x1000 +#define TOP_DARJEELING_MMIO_SIZE_BYTES 0x20000 + +#endif // __ASSEMBLER__ + +#endif // OPENTITAN_HW_TOP_DARJEELING_SW_AUTOGEN_TOP_DARJEELING_SOC_DBG_MEMORY_H_ diff --git a/hw/top_darjeeling/sw/autogen/top_darjeeling_soc_mbx.c b/hw/top_darjeeling/sw/autogen/top_darjeeling_soc_mbx.c new file mode 100644 index 0000000000000..e0c9b0f18676b --- /dev/null +++ b/hw/top_darjeeling/sw/autogen/top_darjeeling_soc_mbx.c @@ -0,0 +1,5 @@ +// Copyright lowRISC contributors. +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 + +#include "hw/top_darjeeling/sw/autogen/top_darjeeling_soc_mbx.h" diff --git a/hw/top_darjeeling/sw/autogen/top_darjeeling_soc_mbx.h b/hw/top_darjeeling/sw/autogen/top_darjeeling_soc_mbx.h new file mode 100644 index 0000000000000..be0b616c9462a --- /dev/null +++ b/hw/top_darjeeling/sw/autogen/top_darjeeling_soc_mbx.h @@ -0,0 +1,211 @@ +// Copyright lowRISC contributors. +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 + +#ifndef OPENTITAN_HW_TOP_DARJEELING_SW_AUTOGEN_TOP_DARJEELING_SOC_MBX_H_ +#define OPENTITAN_HW_TOP_DARJEELING_SW_AUTOGEN_TOP_DARJEELING_SOC_MBX_H_ + +#include "top_darjeeling_flash_ctrl_dummy.h" +#include "top_darjeeling_keymgr_dummy.h" + +/** + * @file + * @brief Top-specific Definitions + * + * This file contains preprocessor and type definitions for use within the + * device C/C++ codebase. + * + * These definitions are for information that depends on the top-specific chip + * configuration, which includes: + * - Device Memory Information (for Peripherals and Memory) + * - PLIC Interrupt ID Names and Source Mappings + * - Alert ID Names and Source Mappings + * - Pinmux Pin/Select Names + * - Power Manager Wakeups + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Peripheral base address for soc device on mbx0 in top darjeeling. + * + * This should be used with #mmio_region_from_addr to access the memory-mapped + * registers associated with the peripheral (usually via a DIF). + */ +#define TOP_DARJEELING_MBX0_SOC_BASE_ADDR 0x1465000u + +/** + * Peripheral size for soc device on mbx0 in top darjeeling. + * + * This is the size (in bytes) of the peripheral's reserved memory area. All + * memory-mapped registers associated with this peripheral should have an + * address between #TOP_DARJEELING_MBX0_SOC_BASE_ADDR and + * `TOP_DARJEELING_MBX0_SOC_BASE_ADDR + TOP_DARJEELING_MBX0_SOC_SIZE_BYTES`. + */ +#define TOP_DARJEELING_MBX0_SOC_SIZE_BYTES 0x20u + +/** + * Peripheral base address for soc device on mbx1 in top darjeeling. + * + * This should be used with #mmio_region_from_addr to access the memory-mapped + * registers associated with the peripheral (usually via a DIF). + */ +#define TOP_DARJEELING_MBX1_SOC_BASE_ADDR 0x1465100u + +/** + * Peripheral size for soc device on mbx1 in top darjeeling. + * + * This is the size (in bytes) of the peripheral's reserved memory area. All + * memory-mapped registers associated with this peripheral should have an + * address between #TOP_DARJEELING_MBX1_SOC_BASE_ADDR and + * `TOP_DARJEELING_MBX1_SOC_BASE_ADDR + TOP_DARJEELING_MBX1_SOC_SIZE_BYTES`. + */ +#define TOP_DARJEELING_MBX1_SOC_SIZE_BYTES 0x20u + +/** + * Peripheral base address for soc device on mbx2 in top darjeeling. + * + * This should be used with #mmio_region_from_addr to access the memory-mapped + * registers associated with the peripheral (usually via a DIF). + */ +#define TOP_DARJEELING_MBX2_SOC_BASE_ADDR 0x1465200u + +/** + * Peripheral size for soc device on mbx2 in top darjeeling. + * + * This is the size (in bytes) of the peripheral's reserved memory area. All + * memory-mapped registers associated with this peripheral should have an + * address between #TOP_DARJEELING_MBX2_SOC_BASE_ADDR and + * `TOP_DARJEELING_MBX2_SOC_BASE_ADDR + TOP_DARJEELING_MBX2_SOC_SIZE_BYTES`. + */ +#define TOP_DARJEELING_MBX2_SOC_SIZE_BYTES 0x20u + +/** + * Peripheral base address for soc device on mbx3 in top darjeeling. + * + * This should be used with #mmio_region_from_addr to access the memory-mapped + * registers associated with the peripheral (usually via a DIF). + */ +#define TOP_DARJEELING_MBX3_SOC_BASE_ADDR 0x1465300u + +/** + * Peripheral size for soc device on mbx3 in top darjeeling. + * + * This is the size (in bytes) of the peripheral's reserved memory area. All + * memory-mapped registers associated with this peripheral should have an + * address between #TOP_DARJEELING_MBX3_SOC_BASE_ADDR and + * `TOP_DARJEELING_MBX3_SOC_BASE_ADDR + TOP_DARJEELING_MBX3_SOC_SIZE_BYTES`. + */ +#define TOP_DARJEELING_MBX3_SOC_SIZE_BYTES 0x20u + +/** + * Peripheral base address for soc device on mbx4 in top darjeeling. + * + * This should be used with #mmio_region_from_addr to access the memory-mapped + * registers associated with the peripheral (usually via a DIF). + */ +#define TOP_DARJEELING_MBX4_SOC_BASE_ADDR 0x1465400u + +/** + * Peripheral size for soc device on mbx4 in top darjeeling. + * + * This is the size (in bytes) of the peripheral's reserved memory area. All + * memory-mapped registers associated with this peripheral should have an + * address between #TOP_DARJEELING_MBX4_SOC_BASE_ADDR and + * `TOP_DARJEELING_MBX4_SOC_BASE_ADDR + TOP_DARJEELING_MBX4_SOC_SIZE_BYTES`. + */ +#define TOP_DARJEELING_MBX4_SOC_SIZE_BYTES 0x20u + +/** + * Peripheral base address for soc device on mbx5 in top darjeeling. + * + * This should be used with #mmio_region_from_addr to access the memory-mapped + * registers associated with the peripheral (usually via a DIF). + */ +#define TOP_DARJEELING_MBX5_SOC_BASE_ADDR 0x1465500u + +/** + * Peripheral size for soc device on mbx5 in top darjeeling. + * + * This is the size (in bytes) of the peripheral's reserved memory area. All + * memory-mapped registers associated with this peripheral should have an + * address between #TOP_DARJEELING_MBX5_SOC_BASE_ADDR and + * `TOP_DARJEELING_MBX5_SOC_BASE_ADDR + TOP_DARJEELING_MBX5_SOC_SIZE_BYTES`. + */ +#define TOP_DARJEELING_MBX5_SOC_SIZE_BYTES 0x20u + +/** + * Peripheral base address for soc device on mbx6 in top darjeeling. + * + * This should be used with #mmio_region_from_addr to access the memory-mapped + * registers associated with the peripheral (usually via a DIF). + */ +#define TOP_DARJEELING_MBX6_SOC_BASE_ADDR 0x1465600u + +/** + * Peripheral size for soc device on mbx6 in top darjeeling. + * + * This is the size (in bytes) of the peripheral's reserved memory area. All + * memory-mapped registers associated with this peripheral should have an + * address between #TOP_DARJEELING_MBX6_SOC_BASE_ADDR and + * `TOP_DARJEELING_MBX6_SOC_BASE_ADDR + TOP_DARJEELING_MBX6_SOC_SIZE_BYTES`. + */ +#define TOP_DARJEELING_MBX6_SOC_SIZE_BYTES 0x20u + +/** + * Peripheral base address for soc device on mbx_pcie0 in top darjeeling. + * + * This should be used with #mmio_region_from_addr to access the memory-mapped + * registers associated with the peripheral (usually via a DIF). + */ +#define TOP_DARJEELING_MBX_PCIE0_SOC_BASE_ADDR 0x1460100u + +/** + * Peripheral size for soc device on mbx_pcie0 in top darjeeling. + * + * This is the size (in bytes) of the peripheral's reserved memory area. All + * memory-mapped registers associated with this peripheral should have an + * address between #TOP_DARJEELING_MBX_PCIE0_SOC_BASE_ADDR and + * `TOP_DARJEELING_MBX_PCIE0_SOC_BASE_ADDR + TOP_DARJEELING_MBX_PCIE0_SOC_SIZE_BYTES`. + */ +#define TOP_DARJEELING_MBX_PCIE0_SOC_SIZE_BYTES 0x20u + +/** + * Peripheral base address for soc device on mbx_pcie1 in top darjeeling. + * + * This should be used with #mmio_region_from_addr to access the memory-mapped + * registers associated with the peripheral (usually via a DIF). + */ +#define TOP_DARJEELING_MBX_PCIE1_SOC_BASE_ADDR 0x1460200u + +/** + * Peripheral size for soc device on mbx_pcie1 in top darjeeling. + * + * This is the size (in bytes) of the peripheral's reserved memory area. All + * memory-mapped registers associated with this peripheral should have an + * address between #TOP_DARJEELING_MBX_PCIE1_SOC_BASE_ADDR and + * `TOP_DARJEELING_MBX_PCIE1_SOC_BASE_ADDR + TOP_DARJEELING_MBX_PCIE1_SOC_SIZE_BYTES`. + */ +#define TOP_DARJEELING_MBX_PCIE1_SOC_SIZE_BYTES 0x20u + + + + +/** + * MMIO Region + * + * MMIO region excludes any memory that is separate from the module + * configuration space, i.e. ROM, main SRAM, and flash are excluded but + * retention SRAM, spi_device memory, or usbdev memory are included. + */ +#define TOP_DARJEELING_MMIO_BASE_ADDR 0x1460100u +#define TOP_DARJEELING_MMIO_SIZE_BYTES 0x5520u + +// Header Extern Guard +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // OPENTITAN_HW_TOP_DARJEELING_SW_AUTOGEN_TOP_DARJEELING_SOC_MBX_H_ diff --git a/hw/top_darjeeling/sw/autogen/top_darjeeling_soc_mbx_memory.h b/hw/top_darjeeling/sw/autogen/top_darjeeling_soc_mbx_memory.h new file mode 100644 index 0000000000000..b07882541ea39 --- /dev/null +++ b/hw/top_darjeeling/sw/autogen/top_darjeeling_soc_mbx_memory.h @@ -0,0 +1,194 @@ +// Copyright lowRISC contributors. +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 + +#ifndef OPENTITAN_HW_TOP_DARJEELING_SW_AUTOGEN_TOP_DARJEELING_SOC_MBX_MEMORY_H_ +#define OPENTITAN_HW_TOP_DARJEELING_SW_AUTOGEN_TOP_DARJEELING_SOC_MBX_MEMORY_H_ + +#include "top_darjeeling_flash_ctrl_dummy.h" +#include "top_darjeeling_keymgr_dummy.h" + +/** + * @file + * @brief Assembler-only Top-Specific Definitions. + * + * This file contains preprocessor definitions for use within assembly code. + * + * These are not shared with C/C++ code because these are only allowed to be + * preprocessor definitions, no data or type declarations are allowed. The + * assembler is also stricter about literals (not allowing suffixes for + * signed/unsigned which are sensible to use for unsigned values in C/C++). + */ + +// Include guard for assembler +#ifdef __ASSEMBLER__ + + + +/** + * Peripheral base address for soc device on mbx0 in top darjeeling. + * + * This should be used with #mmio_region_from_addr to access the memory-mapped + * registers associated with the peripheral (usually via a DIF). + */ +#define TOP_DARJEELING_MBX0_SOC_BASE_ADDR 0x1465000 + +/** + * Peripheral size for soc device on mbx0 in top darjeeling. + * + * This is the size (in bytes) of the peripheral's reserved memory area. All + * memory-mapped registers associated with this peripheral should have an + * address between #TOP_DARJEELING_MBX0_SOC_BASE_ADDR and + * `TOP_DARJEELING_MBX0_SOC_BASE_ADDR + TOP_DARJEELING_MBX0_SOC_SIZE_BYTES`. + */ +#define TOP_DARJEELING_MBX0_SOC_SIZE_BYTES 0x20 +/** + * Peripheral base address for soc device on mbx1 in top darjeeling. + * + * This should be used with #mmio_region_from_addr to access the memory-mapped + * registers associated with the peripheral (usually via a DIF). + */ +#define TOP_DARJEELING_MBX1_SOC_BASE_ADDR 0x1465100 + +/** + * Peripheral size for soc device on mbx1 in top darjeeling. + * + * This is the size (in bytes) of the peripheral's reserved memory area. All + * memory-mapped registers associated with this peripheral should have an + * address between #TOP_DARJEELING_MBX1_SOC_BASE_ADDR and + * `TOP_DARJEELING_MBX1_SOC_BASE_ADDR + TOP_DARJEELING_MBX1_SOC_SIZE_BYTES`. + */ +#define TOP_DARJEELING_MBX1_SOC_SIZE_BYTES 0x20 +/** + * Peripheral base address for soc device on mbx2 in top darjeeling. + * + * This should be used with #mmio_region_from_addr to access the memory-mapped + * registers associated with the peripheral (usually via a DIF). + */ +#define TOP_DARJEELING_MBX2_SOC_BASE_ADDR 0x1465200 + +/** + * Peripheral size for soc device on mbx2 in top darjeeling. + * + * This is the size (in bytes) of the peripheral's reserved memory area. All + * memory-mapped registers associated with this peripheral should have an + * address between #TOP_DARJEELING_MBX2_SOC_BASE_ADDR and + * `TOP_DARJEELING_MBX2_SOC_BASE_ADDR + TOP_DARJEELING_MBX2_SOC_SIZE_BYTES`. + */ +#define TOP_DARJEELING_MBX2_SOC_SIZE_BYTES 0x20 +/** + * Peripheral base address for soc device on mbx3 in top darjeeling. + * + * This should be used with #mmio_region_from_addr to access the memory-mapped + * registers associated with the peripheral (usually via a DIF). + */ +#define TOP_DARJEELING_MBX3_SOC_BASE_ADDR 0x1465300 + +/** + * Peripheral size for soc device on mbx3 in top darjeeling. + * + * This is the size (in bytes) of the peripheral's reserved memory area. All + * memory-mapped registers associated with this peripheral should have an + * address between #TOP_DARJEELING_MBX3_SOC_BASE_ADDR and + * `TOP_DARJEELING_MBX3_SOC_BASE_ADDR + TOP_DARJEELING_MBX3_SOC_SIZE_BYTES`. + */ +#define TOP_DARJEELING_MBX3_SOC_SIZE_BYTES 0x20 +/** + * Peripheral base address for soc device on mbx4 in top darjeeling. + * + * This should be used with #mmio_region_from_addr to access the memory-mapped + * registers associated with the peripheral (usually via a DIF). + */ +#define TOP_DARJEELING_MBX4_SOC_BASE_ADDR 0x1465400 + +/** + * Peripheral size for soc device on mbx4 in top darjeeling. + * + * This is the size (in bytes) of the peripheral's reserved memory area. All + * memory-mapped registers associated with this peripheral should have an + * address between #TOP_DARJEELING_MBX4_SOC_BASE_ADDR and + * `TOP_DARJEELING_MBX4_SOC_BASE_ADDR + TOP_DARJEELING_MBX4_SOC_SIZE_BYTES`. + */ +#define TOP_DARJEELING_MBX4_SOC_SIZE_BYTES 0x20 +/** + * Peripheral base address for soc device on mbx5 in top darjeeling. + * + * This should be used with #mmio_region_from_addr to access the memory-mapped + * registers associated with the peripheral (usually via a DIF). + */ +#define TOP_DARJEELING_MBX5_SOC_BASE_ADDR 0x1465500 + +/** + * Peripheral size for soc device on mbx5 in top darjeeling. + * + * This is the size (in bytes) of the peripheral's reserved memory area. All + * memory-mapped registers associated with this peripheral should have an + * address between #TOP_DARJEELING_MBX5_SOC_BASE_ADDR and + * `TOP_DARJEELING_MBX5_SOC_BASE_ADDR + TOP_DARJEELING_MBX5_SOC_SIZE_BYTES`. + */ +#define TOP_DARJEELING_MBX5_SOC_SIZE_BYTES 0x20 +/** + * Peripheral base address for soc device on mbx6 in top darjeeling. + * + * This should be used with #mmio_region_from_addr to access the memory-mapped + * registers associated with the peripheral (usually via a DIF). + */ +#define TOP_DARJEELING_MBX6_SOC_BASE_ADDR 0x1465600 + +/** + * Peripheral size for soc device on mbx6 in top darjeeling. + * + * This is the size (in bytes) of the peripheral's reserved memory area. All + * memory-mapped registers associated with this peripheral should have an + * address between #TOP_DARJEELING_MBX6_SOC_BASE_ADDR and + * `TOP_DARJEELING_MBX6_SOC_BASE_ADDR + TOP_DARJEELING_MBX6_SOC_SIZE_BYTES`. + */ +#define TOP_DARJEELING_MBX6_SOC_SIZE_BYTES 0x20 +/** + * Peripheral base address for soc device on mbx_pcie0 in top darjeeling. + * + * This should be used with #mmio_region_from_addr to access the memory-mapped + * registers associated with the peripheral (usually via a DIF). + */ +#define TOP_DARJEELING_MBX_PCIE0_SOC_BASE_ADDR 0x1460100 + +/** + * Peripheral size for soc device on mbx_pcie0 in top darjeeling. + * + * This is the size (in bytes) of the peripheral's reserved memory area. All + * memory-mapped registers associated with this peripheral should have an + * address between #TOP_DARJEELING_MBX_PCIE0_SOC_BASE_ADDR and + * `TOP_DARJEELING_MBX_PCIE0_SOC_BASE_ADDR + TOP_DARJEELING_MBX_PCIE0_SOC_SIZE_BYTES`. + */ +#define TOP_DARJEELING_MBX_PCIE0_SOC_SIZE_BYTES 0x20 +/** + * Peripheral base address for soc device on mbx_pcie1 in top darjeeling. + * + * This should be used with #mmio_region_from_addr to access the memory-mapped + * registers associated with the peripheral (usually via a DIF). + */ +#define TOP_DARJEELING_MBX_PCIE1_SOC_BASE_ADDR 0x1460200 + +/** + * Peripheral size for soc device on mbx_pcie1 in top darjeeling. + * + * This is the size (in bytes) of the peripheral's reserved memory area. All + * memory-mapped registers associated with this peripheral should have an + * address between #TOP_DARJEELING_MBX_PCIE1_SOC_BASE_ADDR and + * `TOP_DARJEELING_MBX_PCIE1_SOC_BASE_ADDR + TOP_DARJEELING_MBX_PCIE1_SOC_SIZE_BYTES`. + */ +#define TOP_DARJEELING_MBX_PCIE1_SOC_SIZE_BYTES 0x20 + +/** + * MMIO Region + * + * MMIO region excludes any memory that is separate from the module + * configuration space, i.e. ROM, main SRAM, and flash are excluded but + * retention SRAM, spi_device memory, or usbdev memory are included. + */ +#define TOP_DARJEELING_MMIO_BASE_ADDR 0x1460100 +#define TOP_DARJEELING_MMIO_SIZE_BYTES 0x5520 + +#endif // __ASSEMBLER__ + +#endif // OPENTITAN_HW_TOP_DARJEELING_SW_AUTOGEN_TOP_DARJEELING_SOC_MBX_MEMORY_H_ diff --git a/hw/top_earlgrey/data/autogen/top_earlgrey.gen.hjson b/hw/top_earlgrey/data/autogen/top_earlgrey.gen.hjson index c82d7060678c7..a63d07b36f428 100644 --- a/hw/top_earlgrey/data/autogen/top_earlgrey.gen.hjson +++ b/hw/top_earlgrey/data/autogen/top_earlgrey.gen.hjson @@ -524,6 +524,7 @@ { name: hart desc: The main address space, shared between the CPU and DM + default: true } ] module: diff --git a/hw/top_earlgrey/data/top_earlgrey.hjson b/hw/top_earlgrey/data/top_earlgrey.hjson index fe30cc4ed3480..1678ab05ea910 100644 --- a/hw/top_earlgrey/data/top_earlgrey.hjson +++ b/hw/top_earlgrey/data/top_earlgrey.hjson @@ -171,7 +171,7 @@ // all peripherals, though not every peripheral will be accessible to every // host in that address space--Access privileges are separate from addresses. addr_spaces: [ - { name: "hart", desc: "The main address space, shared between the CPU and DM"}, + { name: "hart", desc: "The main address space, shared between the CPU and DM", default: true}, ] // `module` defines the peripherals. diff --git a/hw/top_englishbreakfast/data/top_englishbreakfast.hjson b/hw/top_englishbreakfast/data/top_englishbreakfast.hjson index 28a26400cd9d8..0403fb873537b 100644 --- a/hw/top_englishbreakfast/data/top_englishbreakfast.hjson +++ b/hw/top_englishbreakfast/data/top_englishbreakfast.hjson @@ -172,7 +172,7 @@ // all peripherals, though not every peripheral will be accessible to every // host in that address space--Access privileges are separate from addresses. addr_spaces: [ - { name: "hart", desc: "The main address space, shared between the CPU and DM"}, + { name: "hart", desc: "The main address space, shared between the CPU and DM", default: true}, ] // `module` defines the peripherals. diff --git a/util/topgen.py b/util/topgen.py index e442352d14d8d..f0fb389957767 100755 --- a/util/topgen.py +++ b/util/topgen.py @@ -776,30 +776,38 @@ def render_template(template_path: str, rendered_path: Path, **other_info): with rendered_path.open(mode="w", encoding="UTF-8") as fout: fout.write(template_contents) - # The Rust file needs some complex information, so we initialize this - # object to store it. - rs_helper = TopGenRust(completecfg, name_to_block, version_stamp) + for addr_space in completecfg['addr_spaces']: + default_addr_space = addr_space.get('default', False) - rust_files = [("toplevel_mod.rs.tpl", "mod.rs"), - ("toplevel.rs.tpl", f"top_{topname}.rs"), - ("toplevel_memory.rs.tpl", f"top_{topname}_memory.rs")] + addr_space_suffix = "" + if not default_addr_space: + addr_space_suffix = "_" + addr_space['name'] - # Creating Rust output directory - rsformat_dir = out_path / "sw/autogen/chip/" - rsformat_dir.mkdir(parents=True, exist_ok=True) + # The Rust file needs some complex information, so we initialize this + # object to store it. + rs_helper = TopGenRust(completecfg, name_to_block, version_stamp, addr_space['name']) + + rust_files = [("toplevel_mod.rs.tpl", "mod.rs"), + ("toplevel.rs.tpl", f"top_{topname}{addr_space_suffix}.rs"), + ("toplevel_memory.rs.tpl", f"top_{topname}{addr_space_suffix}_memory.rs")] - # Generating Rust device description for external sw usage - for (template, source) in rust_files: - render_template(topgen_template_path / template, - rsformat_dir / source, - helper=rs_helper) + # Creating Rust output directory + rsformat_dir = out_path / "sw/autogen/chip/" + rsformat_dir.mkdir(parents=True, exist_ok=True) - # Generating Rust host-side files - rsformat_dir = src_tree_top / "sw/host/opentitanlib/src/chip/autogen" - rsformat_dir.mkdir(parents=True, exist_ok=True) - render_template(topgen_template_path / "host_toplevel.rs.tpl", - rsformat_dir / f"{topname}.rs", - helper=rs_helper) + # Generating Rust device description for external sw usage + for (template, source) in rust_files: + render_template(topgen_template_path / template, + rsformat_dir / source, + helper=rs_helper) + + if default_addr_space: + # Generating Rust host-side files + rsformat_dir = src_tree_top / "sw/host/opentitanlib/src/chip/autogen" + rsformat_dir.mkdir(parents=True, exist_ok=True) + render_template(topgen_template_path / "host_toplevel.rs.tpl", + rsformat_dir / f"{topname}.rs", + helper=rs_helper) def _process_top(topcfg, args, repo_top_path, out_path, pass_idx): @@ -1286,7 +1294,7 @@ def render_template(template_path: str, rendered_path: Path, fout.write(template_contents) # Header for SV files - gencmd = warnhdr + """// + gencmd_sv = warnhdr + """// // util/topgen.py -t hw/top_{topname}/data/top_{topname}.hjson \\ // -o hw/top_{topname}/ \\ // --rnd_cnst_seed \\ @@ -1297,7 +1305,7 @@ def render_template(template_path: str, rendered_path: Path, # "toplevel.sv.tpl" -> "rtl/autogen/top_{topname}.sv" render_template(TOPGEN_TEMPLATE_PATH / "toplevel.sv.tpl", out_path / f"rtl/autogen/top_{topname}.sv", - gencmd=gencmd) + gencmd=gencmd_sv) # Multiple chip-levels (ASIC, FPGA, Verilator, etc) for target in topcfg["targets"]: @@ -1305,75 +1313,94 @@ def render_template(template_path: str, rendered_path: Path, render_template(TOPGEN_TEMPLATE_PATH / "chiplevel.sv.tpl", out_path / f"rtl/autogen/chip_{topname}_{target_name}.sv", - gencmd=gencmd, + gencmd=gencmd_sv, target=target) - # The C / SV file needs some complex information, so we initialize this - # object to store it. - c_helper = TopGenCTest(completecfg, name_to_block) - - # "toplevel_pkg.sv.tpl" -> "rtl/autogen/top_{topname}_pkg.sv" - render_template(TOPGEN_TEMPLATE_PATH / "toplevel_pkg.sv.tpl", - out_path / f"rtl/autogen/top_{topname}_pkg.sv", - helper=c_helper, - gencmd=gencmd) - # compile-time random netlist constants render_template(TOPGEN_TEMPLATE_PATH / "toplevel_rnd_cnst_pkg.sv.tpl", out_path / f"rtl/autogen/top_{topname}_rnd_cnst_pkg.sv", - gencmd=gencmd) - - # Since SW does not use FuseSoC and instead expects those files always - # to be in hw/top_{topname}/sw/autogen, we currently create these files - # twice: - # - Once under out_path/sw/autogen - # - Once under hw/top_{topname}/sw/autogen - root_paths = [out_path.resolve(), SRCTREE_TOP] - out_paths = [ - out_path.resolve(), - (SRCTREE_TOP / "hw/top_{}/".format(topname)).resolve() - ] - for idx, path in enumerate(out_paths): - # C Header + C File + Clang-format file - - # "clang-format" -> "sw/autogen/.clang-format" - cformat_tplpath = TOPGEN_TEMPLATE_PATH / "clang-format" - cformat_dir = path / "sw/autogen" - cformat_dir.mkdir(parents=True, exist_ok=True) - cformat_path = cformat_dir / ".clang-format" - cformat_path.write_text(cformat_tplpath.read_text()) - - # Save the header macro prefix into `c_helper` - rel_header_dir = cformat_dir.relative_to(root_paths[idx]) - c_helper.header_macro_prefix = ( - "OPENTITAN_" + str(rel_header_dir).replace("/", "_").upper()) - - # "top_{topname}.h.tpl" -> "sw/autogen/top_{topname}.h" - cheader_path = cformat_dir / f"top_{topname}.h" - render_template(TOPGEN_TEMPLATE_PATH / "toplevel.h.tpl", - cheader_path, - helper=c_helper) - - # Save the relative header path into `c_helper` - rel_header_path = cheader_path.relative_to(root_paths[idx]) - c_helper.header_path = str(rel_header_path) - - # "toplevel.c.tpl" -> "sw/autogen/top_{topname}.c" - render_template(TOPGEN_TEMPLATE_PATH / "toplevel.c.tpl", - cformat_dir / f"top_{topname}.c", - helper=c_helper) - - # "toplevel_memory.ld.tpl" -> "sw/autogen/top_{topname}_memory.ld" - render_template(TOPGEN_TEMPLATE_PATH / "toplevel_memory.ld.tpl", - cformat_dir / f"top_{topname}_memory.ld", - helper=c_helper) - - # "toplevel_memory.h.tpl" -> "sw/autogen/top_{topname}_memory.h" - memory_cheader_path = cformat_dir / f"top_{topname}_memory.h" - render_template(TOPGEN_TEMPLATE_PATH / "toplevel_memory.h.tpl", - memory_cheader_path, - helper=c_helper) + gencmd=gencmd_sv) + + for addr_space in topcfg['addr_spaces']: + default_addr_space = addr_space.get('default', False) + + addr_space_suffix = "" + if not default_addr_space: + addr_space_suffix = "_" + addr_space['name'] + + # The C / SV file needs some complex information, so we initialize this + # object to store it. + c_helper = TopGenCTest(completecfg, name_to_block, addr_space['name']) + + # "toplevel_pkg.sv.tpl" -> + # "rtl/autogen/top_{topname}{topname}{addr_space_suffix}_pkg.sv" + render_template(TOPGEN_TEMPLATE_PATH / "toplevel_pkg.sv.tpl", + out_path / f"rtl/autogen/top_{topname}{addr_space_suffix}_pkg.sv", + helper=c_helper, + gencmd=gencmd_sv) + + # Since SW does not use FuseSoC and instead expects those files always + # to be in hw/top_{topname}/sw/autogen, we currently create these files + # twice: + # - Once under out_path/sw/autogen + # - Once under hw/top_{topname}/sw/autogen + root_paths = [out_path.resolve(), SRCTREE_TOP] + out_paths = [ + out_path.resolve(), + (SRCTREE_TOP / "hw/top_{}/".format(topname)).resolve() + ] + for idx, path in enumerate(out_paths): + # C Header + C File + Clang-format file + + # "clang-format" -> "sw/autogen/.clang-format" + cformat_tplpath = TOPGEN_TEMPLATE_PATH / "clang-format" + cformat_dir = path / "sw/autogen" + cformat_dir.mkdir(parents=True, exist_ok=True) + cformat_path = cformat_dir / ".clang-format" + cformat_path.write_text(cformat_tplpath.read_text()) + + # Save the header macro prefix into `c_helper` + rel_header_dir = cformat_dir.relative_to(root_paths[idx]) + c_helper.header_macro_prefix = ( + "OPENTITAN_" + str(rel_header_dir).replace("/", "_").upper()) + + # "top_{topname}.h.tpl" -> "sw/autogen/top_{topname}{addr_space_suffix}.h" + cheader_path = cformat_dir / f"top_{topname}{addr_space_suffix}.h" + render_template(TOPGEN_TEMPLATE_PATH / "toplevel.h.tpl", + cheader_path, + helper=c_helper) + + # Save the relative header path into `c_helper` + rel_header_path = cheader_path.relative_to(root_paths[idx]) + c_helper.header_path = str(rel_header_path) + + # "toplevel.c.tpl" -> "sw/autogen/top_{topname}{addr_space_suffix}.c" + render_template(TOPGEN_TEMPLATE_PATH / "toplevel.c.tpl", + cformat_dir / f"top_{topname}{addr_space_suffix}.c", + helper=c_helper) + + # "toplevel_memory.h.tpl" -> "sw/autogen/top_{topname}{addr_space_suffix}_memory.h" + memory_cheader_path = cformat_dir / f"top_{topname}{addr_space_suffix}_memory.h" + render_template(TOPGEN_TEMPLATE_PATH / "toplevel_memory.h.tpl", + memory_cheader_path, + helper=c_helper) + + if default_addr_space: + # "toplevel_memory.ld.tpl" -> + # "sw/autogen/top_{topname}{addr_space_suffix}_memory.ld" + render_template(TOPGEN_TEMPLATE_PATH / "toplevel_memory.ld.tpl", + cformat_dir / f"top_{topname}{addr_space_suffix}_memory.ld", + helper=c_helper) + + # Auto-generate tests in "sw/device/tests/autogen" area. + gencmd = warnhdr + GENCMD.format(topname=topname) + for fname in ["plic_all_irqs_test.c", "alert_test.c", "BUILD"]: + outfile = SRCTREE_TOP / f"sw/device/tests/autogen/top_{topname}" / fname + render_template(TOPGEN_TEMPLATE_PATH / f"{fname}.tpl", + outfile, + helper=c_helper, + gencmd=gencmd) # generate chip level xbar and alert_handler TB tb_files = [ @@ -1387,7 +1414,7 @@ def render_template(template_path: str, rendered_path: Path, template_contents = generate_top(completecfg, name_to_block, str(xbar_chip_data_path), - gencmd=gencmd) + gencmd=gencmd_sv) rendered_dir = out_path / "dv/autogen" rendered_dir.mkdir(parents=True, exist_ok=True) @@ -1412,15 +1439,6 @@ def render_template(template_path: str, rendered_path: Path, # generate documentation for toplevel gen_top_docs(completecfg, c_helper, out_path) - # Auto-generate tests in "sw/device/tests/autogen" area. - gencmd = warnhdr + GENCMD.format(topname=topname) - for fname in ["plic_all_irqs_test.c", "alert_test.c", "BUILD"]: - outfile = SRCTREE_TOP / f"sw/device/tests/autogen/top_{topname}" / fname - render_template(TOPGEN_TEMPLATE_PATH / f"{fname}.tpl", - outfile, - helper=c_helper, - gencmd=gencmd) - if __name__ == "__main__": main() diff --git a/util/topgen/c.py b/util/topgen/c.py index ad7f1c42f49fa..94255f901cd19 100644 --- a/util/topgen/c.py +++ b/util/topgen/c.py @@ -103,7 +103,7 @@ def render_definition(self): class TopGenC: - def __init__(self, top_info, name_to_block: Dict[str, IpBlock]): + def __init__(self, top_info, name_to_block: Dict[str, IpBlock], addr_space: str): self.top = top_info self._top_name = Name(["top"]) + Name.from_snake_case(top_info["name"]) self._name_to_block = name_to_block @@ -111,8 +111,15 @@ def __init__(self, top_info, name_to_block: Dict[str, IpBlock]): # The .c file needs the .h file's relative path, store it here self.header_path = None - # TODO: Don't hardcode the address space used for software. - self.addr_space = "hart" + self.addr_space = addr_space + + # Determine default address space from the top config + self.default_addr_space = None + for addr_space in top_info['addr_spaces']: + default = addr_space.get('default', False) + if default: + self.default_addr_space = addr_space['name'] + assert self.default_addr_space is not None, "Missing default addr_space" self._init_plic_targets() self._init_plic_mapping() @@ -125,6 +132,28 @@ def __init__(self, top_info, name_to_block: Dict[str, IpBlock]): self._init_clkmgr_clocks() self._init_mmio_region() + def all_device_regions(self) -> Dict[str, MemoryRegion]: + '''Return a list of MemoryRegion objects for all devices on the bus + ''' + device_regions = defaultdict(dict) + for inst in self.top['module']: + block = self._name_to_block[inst['type']] + for if_name, rb in block.reg_blocks.items(): + full_if = (inst['name'], if_name) + full_if_name = Name.from_snake_case(full_if[0]) + if if_name is not None: + full_if_name += Name.from_snake_case(if_name) + + name = self._top_name + full_if_name + base, size = get_base_and_size(self._name_to_block, + inst, if_name) + + base_address_int = list(base.values())[0] + region = MemoryRegion(name, base_address_int, size) + device_regions[inst['name']].update({if_name: region}) + + return device_regions + def devices(self) -> List[Tuple[Tuple[str, Optional[str]], MemoryRegion]]: '''Return a list of MemoryRegion objects for devices on the bus diff --git a/util/topgen/c_test.py b/util/topgen/c_test.py index c9d134f22a3df..a8621b3473c0f 100644 --- a/util/topgen/c_test.py +++ b/util/topgen/c_test.py @@ -59,13 +59,15 @@ def __init__(self, name: str, inst_name: str, base_addr_name: str, class TopGenCTest(TopGenC): - def __init__(self, top_info, name_to_block: Dict[str, IpBlock]): - super().__init__(top_info, name_to_block) + def __init__(self, top_info, name_to_block: Dict[str, IpBlock], addr_space: str): + super().__init__(top_info, name_to_block, addr_space) self.irq_peripherals = self._get_irq_peripherals() self.alert_peripherals = self._get_alert_peripherals() def _get_irq_peripherals(self): + if self.addr_space != self.default_addr_space: + return [] irq_peripherals = [] self.devices() for entry in self.top['module']: @@ -118,8 +120,11 @@ def _get_irq_peripherals(self): return irq_peripherals def _get_alert_peripherals(self): + if self.addr_space != self.default_addr_space: + return [] alert_peripherals = [] - self.devices() + device_regions = self.all_device_regions() + for entry in self.top['module']: inst_name = entry['name'] if inst_name not in self.top["alert_module"]: @@ -131,8 +136,7 @@ def _get_alert_peripherals(self): for item in self.top['module']: if item['name'] == inst_name: name = item['type'] - - regions = self.device_regions[inst_name] + regions = device_regions[inst_name] if "core" in regions: if_name = "core" elif "regs" in regions: diff --git a/util/topgen/rust.py b/util/topgen/rust.py index 6fe1e6e0fc554..f79f005d039cb 100644 --- a/util/topgen/rust.py +++ b/util/topgen/rust.py @@ -195,15 +195,23 @@ def render(self): class TopGenRust: - def __init__(self, top_info, name_to_block: Dict[str, IpBlock], version_stamp: Dict[str, str]): + def __init__(self, top_info, name_to_block: Dict[str, IpBlock], version_stamp: Dict[str, str], + addr_space: str): self.top = top_info self._top_name = Name(["top"]) + Name.from_snake_case(top_info["name"]) self._name_to_block = name_to_block self.regwidth = int(top_info["datawidth"]) self.file_header = RustFileHeader("foo.tpl", version_stamp, len(version_stamp) == 0) - # TODO: Don't hardcode the address space used for software. - self.addr_space = "hart" + self.addr_space = addr_space + + # Determine default address space from the top config + self.default_addr_space = None + for addr_space in top_info['addr_spaces']: + default = addr_space.get('default', False) + if default: + self.default_addr_space = addr_space['name'] + assert self.default_addr_space is not None, "Missing default addr_space" self._init_plic_targets() self._init_plic_mapping() diff --git a/util/topgen/templates/toplevel.c.tpl b/util/topgen/templates/toplevel.c.tpl index e0f0e178a71cf..7fd78ed7fc2a3 100644 --- a/util/topgen/templates/toplevel.c.tpl +++ b/util/topgen/templates/toplevel.c.tpl @@ -3,6 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "${helper.header_path}" +% if helper.addr_space == helper.default_addr_space: /** * PLIC Interrupt Source to Peripheral Map @@ -18,4 +19,5 @@ ${helper.plic_mapping.render_definition()} * This array is a mapping from `${helper.alert_alerts.name.as_c_type()}` to * `${helper.alert_sources.name.as_c_type()}`. */ -${helper.alert_mapping.render_definition()} \ No newline at end of file +${helper.alert_mapping.render_definition()}\ +% endif diff --git a/util/topgen/templates/toplevel.h.tpl b/util/topgen/templates/toplevel.h.tpl index 74b85614cd201..96d04138ebb71 100644 --- a/util/topgen/templates/toplevel.h.tpl +++ b/util/topgen/templates/toplevel.h.tpl @@ -2,8 +2,14 @@ // Licensed under the Apache License, Version 2.0, see LICENSE for details. // SPDX-License-Identifier: Apache-2.0 -#ifndef ${helper.header_macro_prefix}_TOP_${top["name"].upper()}_H_ -#define ${helper.header_macro_prefix}_TOP_${top["name"].upper()}_H_ +<% + if helper.addr_space == helper.default_addr_space: + header_suffix = top["name"].upper() + else: + header_suffix = "_".join([top["name"], helper.addr_space]).upper() +%>\ +#ifndef ${helper.header_macro_prefix}_TOP_${header_suffix}_H_ +#define ${helper.header_macro_prefix}_TOP_${header_suffix}_H_ ## TODO(opentitan-integrated/issues/332): Remove this workaround ## once SW has been refactored to work without flash_ctrl. @@ -106,6 +112,7 @@ extern "C" { % endif % endfor +% if helper.addr_space == helper.default_addr_space: /** * PLIC Interrupt Source Peripheral. * @@ -233,6 +240,7 @@ ${helper.clkmgr_gateable_clocks.render()} * but the clock manager is in control of whether the clock actually is stopped. */ ${helper.clkmgr_hintable_clocks.render()} +% endif /** * MMIO Region @@ -249,4 +257,4 @@ ${helper.clkmgr_hintable_clocks.render()} } // extern "C" #endif -#endif // ${helper.header_macro_prefix}_TOP_${top["name"].upper()}_H_ +#endif // ${helper.header_macro_prefix}_TOP_${header_suffix}_H_ diff --git a/util/topgen/templates/toplevel.rs.tpl b/util/topgen/templates/toplevel.rs.tpl index 9971eead9efae..8565b6dcf9478 100644 --- a/util/topgen/templates/toplevel.rs.tpl +++ b/util/topgen/templates/toplevel.rs.tpl @@ -79,6 +79,7 @@ pub const ${base_addr_name}: usize = ${hex_base_addr}; pub const ${size_bytes_name}: usize = ${hex_size_bytes}; % endif % endfor +% if helper.addr_space == helper.default_addr_space: /// PLIC Interrupt Source Peripheral. /// /// Enumeration used to determine which peripheral asserted the corresponding @@ -171,6 +172,7 @@ ${helper.clkmgr_gateable_clocks.render()} /// but the clock manager is in control of whether the clock actually is stopped. ${helper.clkmgr_hintable_clocks.render()} +% endif /// MMIO Region /// /// MMIO region excludes any memory that is separate from the module diff --git a/util/topgen/templates/toplevel_memory.h.tpl b/util/topgen/templates/toplevel_memory.h.tpl index bd3c73e1117dd..5bc18f311e24e 100644 --- a/util/topgen/templates/toplevel_memory.h.tpl +++ b/util/topgen/templates/toplevel_memory.h.tpl @@ -2,8 +2,14 @@ // Licensed under the Apache License, Version 2.0, see LICENSE for details. // SPDX-License-Identifier: Apache-2.0 -#ifndef ${helper.header_macro_prefix}_TOP_${top["name"].upper()}_MEMORY_H_ -#define ${helper.header_macro_prefix}_TOP_${top["name"].upper()}_MEMORY_H_ +<% + if helper.addr_space == helper.default_addr_space: + header_suffix = top["name"].upper() + else: + header_suffix = "_".join([top["name"], helper.addr_space]).upper() +%>\ +#ifndef ${helper.header_macro_prefix}_TOP_${header_suffix}_MEMORY_H_ +#define ${helper.header_macro_prefix}_TOP_${header_suffix}_MEMORY_H_ ## TODO(opentitan-integrated/issues/332): Remove this workaround ## once SW has been refactored to work without flash_ctrl. @@ -112,4 +118,4 @@ #endif // __ASSEMBLER__ -#endif // ${helper.header_macro_prefix}_TOP_${top["name"].upper()}_MEMORY_H_ +#endif // ${helper.header_macro_prefix}_TOP_${header_suffix}_MEMORY_H_ diff --git a/util/topgen/templates/toplevel_mod.rs.tpl b/util/topgen/templates/toplevel_mod.rs.tpl index 993afb89469e5..2dd153fbae588 100644 --- a/util/topgen/templates/toplevel_mod.rs.tpl +++ b/util/topgen/templates/toplevel_mod.rs.tpl @@ -2,5 +2,19 @@ // Licensed under the Apache License, Version 2.0, see LICENSE for details. // SPDX-License-Identifier: Apache-2.0 -pub mod top_${top["name"]}; -pub mod top_${top["name"]}_memory; +<% + top_name = top["name"] + modules = [] + for addr_space in top["addr_spaces"]: + if addr_space.get('default', False): + modules.append(f"top_{top_name}") + modules.append(f"top_{top_name}_memory") + else: + addr_space_name = addr_space["name"] + modules.append(f"top_{top_name}_{addr_space['name']}") + modules.append(f"top_{top_name}_{addr_space['name']}_memory") + modules.sort() +%>\ +% for module in modules: +pub mod ${module}; +% endfor diff --git a/util/topgen/templates/toplevel_pkg.sv.tpl b/util/topgen/templates/toplevel_pkg.sv.tpl index 50fdb94857d10..d1f190210d58d 100644 --- a/util/topgen/templates/toplevel_pkg.sv.tpl +++ b/util/topgen/templates/toplevel_pkg.sv.tpl @@ -4,8 +4,10 @@ ${gencmd} <% import topgen.lib as lib + +addr_space_suffix = "" if helper.addr_space == helper.default_addr_space else "_" + helper.addr_space %>\ -package top_${top["name"]}_pkg; +package top_${top["name"]}${addr_space_suffix}_pkg; % for (inst_name, if_name), region in helper.devices(): <% if_desc = inst_name if if_name is None else '{} device on {}'.format(if_name, inst_name) @@ -62,6 +64,7 @@ package top_${top["name"]}_pkg; % endif % endfor +% if helper.addr_space == helper.default_addr_space: // Enumeration of alert modules typedef enum int unsigned { % for mod in top["alert_module"]: @@ -172,5 +175,6 @@ package top_${top["name"]}_pkg; `define INOUT_AI inout `define INOUT_AO inout `endif +% endif endpackage diff --git a/util/topgen/validate.py b/util/topgen/validate.py index da214c7257320..cf6c1f276335b 100644 --- a/util/topgen/validate.py +++ b/util/topgen/validate.py @@ -41,7 +41,7 @@ 'type': ['s', 'type of hjson. Shall be "top" always'], 'clocks': ['g', 'group of clock properties'], 'resets': ['l', 'list of resets'], - 'addr_spaces': ['ln', 'list of address spaces'], + 'addr_spaces': ['l', 'list of address spaces'], 'module': ['l', 'list of modules to instantiate'], 'memory': ['l', 'list of memories. At least one memory ' 'is needed to run the software'],