Skip to content

Commit

Permalink
[topgen] Only create pinmux if there is an instance
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Schilling <[email protected]>
  • Loading branch information
Razer6 committed Nov 28, 2024
1 parent e2eb2ae commit 269751c
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 8 deletions.
3 changes: 2 additions & 1 deletion util/topgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,8 @@ def _process_top(
sys.exit()

# Generate Pinmux
generate_pinmux(completecfg, out_path)
if lib.find_module(completecfg['module'], 'pinmux'):
generate_pinmux(completecfg, out_path)

# Generate Pwrmgr if there is an instance
if lib.find_module(completecfg['module'], 'pwrmgr'):
Expand Down
7 changes: 5 additions & 2 deletions util/topgen/gen_top_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"""
from tabulate import tabulate

from .lib import find_module

TABLE_HEADER = '''<!--
DO NOT EDIT THIS FILE DIRECTLY.
It has been generated with the following command:
Expand Down Expand Up @@ -211,5 +213,6 @@ def gen_pinmux_docs(top, c_helper, out_path):


def gen_top_docs(top, c_helper, out_path):
# create pinout / pinmux specific tables for all targets
gen_pinmux_docs(top, c_helper, out_path)
if find_module(top['module'], 'pinmux'):
# create pinout / pinmux specific tables for all targets
gen_pinmux_docs(top, c_helper, out_path)
6 changes: 4 additions & 2 deletions util/topgen/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,8 +864,10 @@ def __init__(self, top_info, name_to_block: Dict[str, IpBlock], enum_type, array
self._init_plic_targets()
self._init_plic_mapping()
self._init_alert_mapping()
self._init_pinmux_mapping()
self._init_pad_mapping()
# Only generate pinmux and pad mappings if there is a pinmux
if find_module(self.top['module'], 'pinmux'):
self._init_pinmux_mapping()
self._init_pad_mapping()
# Only generate pwrmgr mappings if there is a pwrmgr
if find_module(self.top['module'], 'pwrmgr'):
self._init_pwrmgr_wakeups()
Expand Down
7 changes: 4 additions & 3 deletions util/topgen/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1308,9 +1308,10 @@ def merge_top(topcfg: OrderedDict,
# Combine the alert (should be processed prior to xbar)
amend_alert(topcfg, name_to_block)

# Creates input/output list in the pinmux
log.info("Processing PINMUX")
amend_pinmux_io(topcfg, name_to_block)
if lib.find_module(topcfg['module'], 'pinmux'):
# Creates input/output list in the pinmux
log.info("Processing PINMUX")
amend_pinmux_io(topcfg, name_to_block)

# Combine xbar into topcfg
for xbar in xbarobjs:
Expand Down
7 changes: 7 additions & 0 deletions util/topgen/templates/host_toplevel.rs.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// Copyright lowRISC contributors (OpenTitan project).
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
<%
import topgen.lib as lib

has_pinmux = lib.find_module(top['module'], 'pinmux')
%>\

// This file was generated automatically.
// Please do not modify content of this file directly.
Expand All @@ -10,6 +15,7 @@
#![allow(dead_code)]

use crate::with_unknown;
% if has_pinmux:

with_unknown! {
${helper.pinmux_peripheral_in.render_host()}
Expand All @@ -35,3 +41,4 @@ pub mod ujson_alias {
pub type pinmux_mio_out_t = ${helper.pinmux_mio_out.short_name.as_rust_type()};
pub type pinmux_outsel_t = ${helper.pinmux_outsel.short_name.as_rust_type()};
}
% endif
5 changes: 5 additions & 0 deletions util/topgen/templates/toplevel.h.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import textwrap
import topgen.lib as lib

has_pwrmgr = lib.find_module(top['module'], 'pwrmgr')
has_pinmux = lib.find_module(top['module'], 'pinmux')
%>\

#ifndef ${helper.header_macro_prefix}_TOP_${top["name"].upper()}_H_
Expand All @@ -23,7 +24,9 @@ has_pwrmgr = lib.find_module(top['module'], 'pwrmgr')
* - Device Memory Information (for Peripherals and Memory)
* - PLIC Interrupt ID Names and Source Mappings
* - Alert ID Names and Source Mappings
% if has_pinmux:
* - Pinmux Pin/Select Names
% endif
% if has_pwrmgr:
* - Power Manager Wakeups
% endif
Expand Down Expand Up @@ -139,6 +142,7 @@ ${helper.alert_alerts.render()}
* `${helper.alert_sources.name.as_c_type()}`.
*/
${helper.alert_mapping.render_declaration()}
% if has_pinmux:

#define PINMUX_MIO_PERIPH_INSEL_IDX_OFFSET 2

Expand Down Expand Up @@ -180,6 +184,7 @@ ${helper.direct_pads.render()}
* Muxed Pad Selects
*/
${helper.muxed_pads.render()}
% endif
% if has_pwrmgr:

/**
Expand Down
5 changes: 5 additions & 0 deletions util/topgen/templates/toplevel.rs.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import textwrap
import topgen.lib as lib

has_pwrmgr = lib.find_module(top['module'], 'pwrmgr')
has_pinmux = lib.find_module(top['module'], 'pinmux')
%>\
${helper.file_header.render()}
// This file was generated automatically.
Expand All @@ -22,7 +23,9 @@ ${helper.file_header.render()}
//! - Device Memory Information (for Peripherals and Memory)
//! - PLIC Interrupt ID Names and Source Mappings
//! - Alert ID Names and Source Mappings
% if has_pinmux:
//! - Pinmux Pin/Select Names
% endif
% if has_pwrmgr:
//! - Power Manager Wakeups
% endif
Expand Down Expand Up @@ -111,6 +114,7 @@ ${helper.plic_mapping.render_definition()}
/// This array is a mapping from `${helper.alert_alerts.short_name.as_rust_type()}` to
/// `${helper.alert_sources.short_name.as_rust_type()}`.
${helper.alert_mapping.render_definition()}
% if has_pinmux:

// PERIPH_INSEL ranges from 0 to NUM_MIO_PADS + 2 -1}
// 0 and 1 are tied to value 0 and 1
Expand Down Expand Up @@ -139,6 +143,7 @@ ${helper.direct_pads.render(gen_cast=True)}

/// Muxed Pad Selects
${helper.muxed_pads.render(gen_cast=True)}
% endif
% if has_pwrmgr:

/// Power Manager Wakeup Signals
Expand Down
5 changes: 5 additions & 0 deletions util/topgen/templates/toplevel_pkg.sv.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
${gencmd}
<%
import topgen.lib as lib
import topgen.lib as lib

has_pinmux = lib.find_module(top['module'], 'pinmux')
%>\
package top_${top["name"]}_pkg;
% for (inst_name, if_name), region in helper.devices():
Expand Down Expand Up @@ -75,6 +78,7 @@ package top_${top["name"]}_pkg;
% endfor
${lib.Name.from_snake_case("top_" + top["name"] + "_alert_id_count").as_camel_case()}
} alert_id_e;
% if has_pinmux:

// Enumeration of IO power domains.
// Only used in ASIC target.
Expand Down Expand Up @@ -147,6 +151,7 @@ package top_${top["name"]}_pkg;
% endfor
${lib.Name.from_snake_case("dio_pad_count").as_camel_case()}
} dio_pad_e;
% endif

<%
instances = sorted(set(inst for (inst, _), __ in helper.devices()))
Expand Down

0 comments on commit 269751c

Please sign in to comment.