Skip to content

Register frontend: C header generation - #158

Merged
DanielKellerM merged 3 commits into
pulp-platform:develfrom
mosaic-soc:pr/c-headers
Jul 31, 2026
Merged

Register frontend: C header generation#158
DanielKellerM merged 3 commits into
pulp-platform:develfrom
mosaic-soc:pr/c-headers

Conversation

@da-gazzi

Copy link
Copy Markdown
Contributor
  • Add make target idma_sw_all to generate target/sw/idma_reg{32,64}_${N}d_[raw_]regs.h for each generated register frontend.
  • 2 headers are generated: the one without raw in the name uses the PeakRDL c-header plugin to create a struct-based header, the one with raw is generated with the raw-header plugin. The raw version is (with the current version of raw-header) somewhat incomplete as the masks for sub-register bitfields have to be generated/hardcoded externally.
  • The deploy CI job calls this target and deploy.py is amended to edit the appropriate .gitignore; C headers are also checked into deploy branches
  • uv.lock and pyproject.toml amended so the c-header plugin is part of the environment

- This target generates C headers in `target/sw` with both the `raw-header` and `c-header` PeakRDL plugins
- Also added to `deploy` CI job
@da-gazzi
da-gazzi changed the base branch from master to devel July 13, 2026 08:31

@DanielKellerM DanielKellerM left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution. Could you check the comments / changes I requested?

Comment thread idma.mk Outdated
Comment on lines +239 to +242
$(PEAKRDL) c-header $(IDMA_FE_DIR)/reg/idma_reg.rdl -i -o $@ \
-P SysAddrWidth=$(call regwidth,$*) \
-P NumDims=$(call dimension,$*) \
-P Log2NumDims=$(call log2dimension,$(call dimension,$*))

@DanielKellerM DanielKellerM Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Use the rename to keep compatibility with other IPs that consume the sw.
  2. Drop -i since we dont need a fixed absolute address.
  3. Prepend the SPDX header via sed (c-header has no --license_str).
Suggested change
$(PEAKRDL) c-header $(IDMA_FE_DIR)/reg/idma_reg.rdl -i -o $@ \
-P SysAddrWidth=$(call regwidth,$*) \
-P NumDims=$(call dimension,$*) \
-P Log2NumDims=$(call log2dimension,$(call dimension,$*))
$(PEAKRDL) c-header $(IDMA_FE_DIR)/reg/idma_reg.rdl -o $@ \
-b ltoh --type-style hier --rename idma_reg$*d \
-P SysAddrWidth=$(call regwidth,$*) \
-P NumDims=$(call dimension,$*) \
-P Log2NumDims=$(call log2dimension,$(call dimension,$*))
sed -i '1i$(IDMA_C_HDR_LIC)' $@

Comment thread idma.mk
$(IDMA_HTML_DIR)/regs/idma_desc64_reg/index.html:
$(PEAKRDL) html $(IDMA_FE_DIR)/desc64/idma_desc64_reg.rdl -o $(IDMA_HTML_DIR)/regs/idma_desc64_reg

# C header

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding license to generated files

Suggested change
# C header
# C header
IDMA_LICENSE := Copyright 2026 ETH Zurich and University of Bologna.\nSolderpad Hardware License, Version 0.51, see LICENSE for details.\nSPDX-License-Identifier: SHL-0.51
IDMA_C_HDR_LIC := // $(subst \n,\n// ,$(IDMA_LICENSE))\n

Comment thread idma.mk
Comment on lines +250 to +251
$(PEAKRDL) raw-header $(IDMA_FE_DIR)/reg/idma_reg.rdl -o $@ \
--format c \

@DanielKellerM DanielKellerM Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add licensing to the raw header too.

Suggested change
$(PEAKRDL) raw-header $(IDMA_FE_DIR)/reg/idma_reg.rdl -o $@ \
--format c \
$(PEAKRDL) raw-header $(IDMA_FE_DIR)/reg/idma_reg.rdl -o $@ \
--format c \
--license_str="$(IDMA_LICENSE)" \

Comment thread idma.mk Outdated
Comment on lines +271 to +272
IDMA_SW_ALL += $(foreach Y,$(IDMA_FE_IDS),$(IDMA_SW_DIR)/idma_$Y_regs.h)
IDMA_SW_ALL += $(foreach Y,$(IDMA_FE_IDS),$(IDMA_SW_DIR)/idma_$Y_regs_unpacked.h)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extend SW generation to descriptor based frontend:

Suggested change
IDMA_SW_ALL += $(foreach Y,$(IDMA_FE_IDS),$(IDMA_SW_DIR)/idma_$Y_regs.h)
IDMA_SW_ALL += $(foreach Y,$(IDMA_FE_IDS),$(IDMA_SW_DIR)/idma_$Y_regs_unpacked.h)
IDMA_SW_ALL += $(foreach Y,$(IDMA_FE_REGS),$(IDMA_SW_DIR)/idma_$Y_regs.h)
IDMA_SW_ALL += $(foreach Y,$(IDMA_FE_REGS),$(IDMA_SW_DIR)/idma_$Y_regs_unpacked.h)

Comment thread idma.mk Outdated
IDMA_SW_ALL += $(foreach Y,$(IDMA_FE_IDS),$(IDMA_SW_DIR)/idma_$Y_regs_unpacked.h)

# C headers with the "raw-header" plugin
IDMA_SW_ALL += $(foreach Y,$(IDMA_FE_IDS),$(IDMA_SW_DIR)/idma_$Y_raw_regs.h)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same SW for descriptro based frontend

Suggested change
IDMA_SW_ALL += $(foreach Y,$(IDMA_FE_IDS),$(IDMA_SW_DIR)/idma_$Y_raw_regs.h)
IDMA_SW_ALL += $(foreach Y,$(IDMA_FE_REGS),$(IDMA_SW_DIR)/idma_$Y_raw_regs.h)

Comment thread idma.mk
-P SysAddrWidth=$(call regwidth,$*) \
-P NumDims=$(call dimension,$*) \
-P Log2NumDims=$(call log2dimension,$(call dimension,$*))

@DanielKellerM DanielKellerM Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the desc64 rules

Suggested change
$(IDMA_SW_DIR)/idma_desc64_regs.h:
$(PEAKRDL) c-header $(IDMA_FE_DIR)/desc64/idma_desc64_reg.rdl -o $@ \
-b ltoh --type-style hier --rename idma_desc64
sed -i '1i$(IDMA_C_HDR_LIC)' $@
$(IDMA_SW_DIR)/idma_desc64_regs_unpacked.h: $(IDMA_SW_DIR)/idma_desc64_regs.h
sed -e "s/__attribute__ ((__packed__)) //" $< > $@
$(IDMA_SW_DIR)/idma_desc64_raw_regs.h:
$(PEAKRDL) raw-header $(IDMA_FE_DIR)/desc64/idma_desc64_reg.rdl -o $@ \
--format c --base_name idma_desc64 \
--license_str="$(IDMA_LICENSE)"

- the PeakRDL `c-header` plugin generates structs with `__attribute__((__packed__))` which ensures proper packing of fields but can also cause the compiler to emit byte loads/stores to access 32-bit registers, which is definitely not what we want. The `unpacked` version of the C header has the attribute removed.
- The `idma_sw_clean` target had a typo and didn't actually clean anything, this is fixed now.
@da-gazzi

Copy link
Copy Markdown
Contributor Author

Implemented, thanks a lot for reviewing!

@DanielKellerM DanielKellerM left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feedback addressed (rename/type-style/ltoh, SPDX, desc64). Thanks!

@DanielKellerM
DanielKellerM merged commit 56c4a83 into pulp-platform:devel Jul 31, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants