blob: ea214378772f5eb1dbcac61b2e9ef1682ea861ce [file] [log] [blame] [view]
Garret Kelly9eebde02019-10-22 15:36:49 -04001---
Jade Philipoom8891bb42022-03-21 22:04:50 +00002title: "Designing Hardware"
Garret Kelly9eebde02019-10-22 15:36:49 -04003---
4
Scott Johnsoneca03382019-10-22 14:47:45 -07005This document aims to clarify how to get started with a hardware design within the OpenTitan project.
Garret Kelly9eebde02019-10-22 15:36:49 -04006Design in this context nominally refers to a new [Comportable Peripheral]({{< relref "../rm/comportability_specification" >}}) but can include high level constructs like device reset strategy, etc.
Scott Johnsoneca03382019-10-22 14:47:45 -07007This is primarily aimed at creating a new design from scratch, but has sections on how to contribute to an existing design.
8It is targeted to RTL designers to give clarity on the typical process for declaring features, finding others to review, etc.
9We aim for a healthy balance between adding clarity while not over prescribing rules and process.
10There are times when a more regimented approach is warranted, and those will be highlighted in this document.
11Feedback and improvements are welcome.
12
13
14## Stages of a Design
15
Sam Elliott2061d8b2020-04-20 19:56:54 +010016The life stages of a design within the OpenTitan are described in the [Hardware Development Stages]({{< relref "doc/project/development_stages.md" >}}) document.
Scott Johnsoneca03382019-10-22 14:47:45 -070017This separates the life of the design into three broad stages: Specification, In Development, and Signed off.
18This document attempts to give guidance on how to get going with the first stage and have a smooth transition into the Development stage.
19They are not hard and fast rules but methods we have seen work well in the project.
20
21
22## Concept and RFC
23
24The concept of a design might come from a variety of inspirations: a known required module already slated for future product need; a new design needed for a proposed product feature; an inspiration worthy of being discussed more broadly; perhaps even a new approach to an existing design (higher performance; more secure; etc).
25Regardless of the inspiration, the concept should be codified into a brief proposal with basic features.
26This is as opposed to minor modification proposals to an existing design, which can be handled as a GitHub pull request or issue filing associated with the existing design.
27This proposal should be in **Google Doc** medium for agile review capability.
28Ideally this proposal document would be created in the Team Drive, but if the author does not have access to the team drive, they can share a privately-created document.
29
Garret Kelly9eebde02019-10-22 15:36:49 -040030Design proposals should follow the recommended [RFC (Request for Comment)]({{< relref "../project/rfc_process.md" >}}) process, which handles all such proposals.
Alex Bradbury80ff95f2019-11-04 17:00:37 +000031If the RFC potentially contains information that could be certification-sensitive (guidance to be shared), send a note to security@opentitan.org first for feedback.
Scott Johnsoneca03382019-10-22 14:47:45 -070032The OpenTitan Technical Committee may be able to suggest other collaborators to help with early stage review.
33
Scott Johnson8573fa22019-11-01 14:49:56 -070034An example of a canonical RFC will be provided *here* (TODO).
Scott Johnsoneca03382019-10-22 14:47:45 -070035
36
37## Detailed Specification
38
39Once past initial review of the feature set and high level description, as well as potential security review, the full detailed specification should be completed, still in Google Doc form.
Garret Kelly9eebde02019-10-22 15:36:49 -040040The content, form, and format are discussed in the [design methodology]({{< relref "design.md" >}}) and [documentation methodology]({{< relref "../rm/markdown_usage_style.md" >}}) guides.
Scott Johnsoneca03382019-10-22 14:47:45 -070041The outcome of this process should be a specification that is ready for further detailed review by other project members.
42The content and the status of the proposal can be shared with the team.
43
44An example of a canonical detailed specification is the pinmux specification which can be found in the TeamDrive under TechnicalSpecifications --> deprecated, for those that have access to that resource.
Philipp Wagner14a3fee2019-11-21 10:07:02 +000045(Google Docs that have been converted into Markdown on GitHub are archived here).
Scott Johnsoneca03382019-10-22 14:47:45 -070046
47
48## Specification Publication
49
50Once the specification is published to the wider team, the author(s) need to address input, comments, questions, etc., continuing to hone the proposal.
51Other team members should also feel empowered to help address these questions and feedback.
52It is acceptable to keep an unanswered-questions section of the document and move forward where there is agreement.
53
54
55## Initial Skeleton Design
56
57In parallel with publication and review of the specification, the initial skeleton design can commence.
58There are many ways to get past this "big bang" of necessary implementation and get it through eventual code review.
59One recommended method is as follows:
Philipp Wagner14a3fee2019-11-21 10:07:02 +000060* Start with a skeleton that includes a complete or near-complete definition of the register content in Hjson format
61* Combine with a basic Markdown including that file
62* Combine with an IP-top-level Verilog module that instantiates the auto-generated register model (see the [register tool documentation]({{< relref "../rm/register_tool" >}})), includes all of the known IP-level IO, clocking and reset.
Scott Johnsoneca03382019-10-22 14:47:45 -070063
64This is not mandatory but allows the basics to come in first with one review, and the full custom details over time.
65Regardless the first check-ins of course should be compilable, syntax error free,
66[coding style guide](https://github.com/lowRISC/style-guides/blob/master/VerilogCodingStyle.md)
Garret Kelly9eebde02019-10-22 15:36:49 -040067friendly, [Comportability]({{< relref "../rm/comportability_specification" >}}) equivalent, etc., as indicated by the [design methodology user guide]({{< relref "design.md" >}}).
Scott Johnsoneca03382019-10-22 14:47:45 -070068
Philipp Wagner14a3fee2019-11-21 10:07:02 +000069A good example of an initial skeleton design can be seen in [Pull Request #166](https://github.com/lowRISC/opentitan/pull/166) for the AES module.
Scott Johnsoneca03382019-10-22 14:47:45 -070070
Philipp Wagner14a3fee2019-11-21 10:07:02 +000071As part of the GitHub filing process, the Google Doc specification must be converted into a Markdown specification.
72(Tip: there are Google Doc add-ons that can convert the specification into Markdown format).
Scott Johnsoneca03382019-10-22 14:47:45 -070073Once this is completed, any specifications on the Team Drive should be moved to the deprecated section of the drive, with a link at the top indicating that the document is for historical purposes only.
74This applies only for those specifications that originated on the Drive.
75
76
77## Full Design
78
Sam Elliott2061d8b2020-04-20 19:56:54 +010079As the design develops within the OpenTitan repository, it transitions into "D0", "D1", etc., [design stages]({{< relref "doc/project/development_stages.md" >}}) and will be eventually plugged into the top level.
Scott Johnsoneca03382019-10-22 14:47:45 -070080Following the recommended best practices for digestible pull requests suggests that continuing to stage the design from the initial skeleton into the full featured design is a good way to make steady progress without over-burdening the reviewers.
81
82## Top Level Inclusion
83
84Once an IP block is ready, it can be included in the top-level design.
85To do so, follow the steps below.
86
87* Get an agreement on if and how the IP block should be integrated.
88* Ensure that the IP block is of acceptable quality.
Philipp Wagner09402b42019-11-21 10:09:21 +000089* Ensure that the top level simulation is not adversely affected.
Scott Johnsoneca03382019-10-22 14:47:45 -070090* Open a Pull Request with the necessary code changes.
91
92If it is not clear on how to proceed, feel free to file an issue requesting assistance.
Eunchan Kim1cfc3be2021-11-23 23:38:11 +000093
94## Change of Interrupts
95
96Changing the interrupts of an IP block needs some extra work in addition to the RTL change.
971. If a DV environment exists, its testbench (`tb.sv`) will need the ports connected.
981. If the IP block has been instantiated in a top-level, that top-level will need re-generating to include the new ports.
991. The auto-generated DIFs will need re-generating.
1001. The PLIC test should also be updated.
101
102Item 1 is reasonably self-explanatory.
103The sections below show how to do items 2-4.
104
105### Update TOP
106
107```console
108$ make -C hw top
109```
110
111After you revise the IP `.hjson`, IP top module, IP register interface, and DV testbench `tb.sv`, you can re-generate top-levels with the command above.
112This reads the `.hjson` file and updates the interrupt signal and re-generates the PLIC module if needed.
113
114### New DIF
115
116Unfortunately, re-generating TOP does not resolve everything.
117If the interrupt names are changed or new interrupts are introduced, the DIF for the IP block should be re-generated.
118
119```console
120$ ./util/make_new_dif.py --mode=regen --only=autogen
121```
122
123The command above updates the DIF (auto-generated part) under `sw/device/lib/dif/`.
124
125If DIF for the IP block already uses the interrupt enums inside, you need to manually revise the reference.
126In most cases, the interrupt name is `kDif`, followed by the IP name in PascalCase (e.g `SpiDevice`), then `Irq`, then the interrupt name in PascalCase (e.g. `RxFull`).
127For example, `kDifSpiDeviceIrqRxFull`.
128To refer to an interrupt in the top-level PLIC enum, the format is `kTopEarlgreyPlicIrqId`, followed by the IP name in PascalCase, then the interrupt name in PascalCase.
129For example, `kTopEarlgreyPlicIrqIdSpiDeviceRxFull`.
130
131### PLIC Unittest
132
133If the number of interrupts has changed, you need to revise the SW unit test manually.
134
135Open `sw/device/lib/dif/dif_rv_plic_unittest.cc` and change the `RV_PLIC_PARAM_NUM_SRC` macro to the current interrupt number.
136Then, find `RV_PLIC_IE0_*_REG_OFFSET`, `RV_PLIC_IP0_*_REG_OFFSET` and revise the Bit value or add lines below if new `IE`, `IP` registers are added.