Garret Kelly | 9eebde0 | 2019-10-22 15:36:49 -0400 | [diff] [blame] | 1 | --- |
Jade Philipoom | 8891bb4 | 2022-03-21 22:04:50 +0000 | [diff] [blame] | 2 | title: "Designing Hardware" |
Garret Kelly | 9eebde0 | 2019-10-22 15:36:49 -0400 | [diff] [blame] | 3 | --- |
| 4 | |
Scott Johnson | eca0338 | 2019-10-22 14:47:45 -0700 | [diff] [blame] | 5 | This document aims to clarify how to get started with a hardware design within the OpenTitan project. |
Garret Kelly | 9eebde0 | 2019-10-22 15:36:49 -0400 | [diff] [blame] | 6 | Design 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 Johnson | eca0338 | 2019-10-22 14:47:45 -0700 | [diff] [blame] | 7 | This is primarily aimed at creating a new design from scratch, but has sections on how to contribute to an existing design. |
| 8 | It is targeted to RTL designers to give clarity on the typical process for declaring features, finding others to review, etc. |
| 9 | We aim for a healthy balance between adding clarity while not over prescribing rules and process. |
| 10 | There are times when a more regimented approach is warranted, and those will be highlighted in this document. |
| 11 | Feedback and improvements are welcome. |
| 12 | |
| 13 | |
| 14 | ## Stages of a Design |
| 15 | |
Sam Elliott | 2061d8b | 2020-04-20 19:56:54 +0100 | [diff] [blame] | 16 | The life stages of a design within the OpenTitan are described in the [Hardware Development Stages]({{< relref "doc/project/development_stages.md" >}}) document. |
Scott Johnson | eca0338 | 2019-10-22 14:47:45 -0700 | [diff] [blame] | 17 | This separates the life of the design into three broad stages: Specification, In Development, and Signed off. |
| 18 | This document attempts to give guidance on how to get going with the first stage and have a smooth transition into the Development stage. |
| 19 | They are not hard and fast rules but methods we have seen work well in the project. |
| 20 | |
| 21 | |
| 22 | ## Concept and RFC |
| 23 | |
| 24 | The 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). |
| 25 | Regardless of the inspiration, the concept should be codified into a brief proposal with basic features. |
| 26 | This 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. |
| 27 | This proposal should be in **Google Doc** medium for agile review capability. |
| 28 | Ideally 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 Kelly | 9eebde0 | 2019-10-22 15:36:49 -0400 | [diff] [blame] | 30 | Design proposals should follow the recommended [RFC (Request for Comment)]({{< relref "../project/rfc_process.md" >}}) process, which handles all such proposals. |
Alex Bradbury | 80ff95f | 2019-11-04 17:00:37 +0000 | [diff] [blame] | 31 | If 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 Johnson | eca0338 | 2019-10-22 14:47:45 -0700 | [diff] [blame] | 32 | The OpenTitan Technical Committee may be able to suggest other collaborators to help with early stage review. |
| 33 | |
Scott Johnson | 8573fa2 | 2019-11-01 14:49:56 -0700 | [diff] [blame] | 34 | An example of a canonical RFC will be provided *here* (TODO). |
Scott Johnson | eca0338 | 2019-10-22 14:47:45 -0700 | [diff] [blame] | 35 | |
| 36 | |
| 37 | ## Detailed Specification |
| 38 | |
| 39 | Once 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 Kelly | 9eebde0 | 2019-10-22 15:36:49 -0400 | [diff] [blame] | 40 | The content, form, and format are discussed in the [design methodology]({{< relref "design.md" >}}) and [documentation methodology]({{< relref "../rm/markdown_usage_style.md" >}}) guides. |
Scott Johnson | eca0338 | 2019-10-22 14:47:45 -0700 | [diff] [blame] | 41 | The outcome of this process should be a specification that is ready for further detailed review by other project members. |
| 42 | The content and the status of the proposal can be shared with the team. |
| 43 | |
| 44 | An 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 Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 45 | (Google Docs that have been converted into Markdown on GitHub are archived here). |
Scott Johnson | eca0338 | 2019-10-22 14:47:45 -0700 | [diff] [blame] | 46 | |
| 47 | |
| 48 | ## Specification Publication |
| 49 | |
| 50 | Once the specification is published to the wider team, the author(s) need to address input, comments, questions, etc., continuing to hone the proposal. |
| 51 | Other team members should also feel empowered to help address these questions and feedback. |
| 52 | It 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 | |
| 57 | In parallel with publication and review of the specification, the initial skeleton design can commence. |
| 58 | There are many ways to get past this "big bang" of necessary implementation and get it through eventual code review. |
| 59 | One recommended method is as follows: |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 60 | * 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 Johnson | eca0338 | 2019-10-22 14:47:45 -0700 | [diff] [blame] | 63 | |
| 64 | This is not mandatory but allows the basics to come in first with one review, and the full custom details over time. |
| 65 | Regardless 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 Kelly | 9eebde0 | 2019-10-22 15:36:49 -0400 | [diff] [blame] | 67 | friendly, [Comportability]({{< relref "../rm/comportability_specification" >}}) equivalent, etc., as indicated by the [design methodology user guide]({{< relref "design.md" >}}). |
Scott Johnson | eca0338 | 2019-10-22 14:47:45 -0700 | [diff] [blame] | 68 | |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 69 | A 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 Johnson | eca0338 | 2019-10-22 14:47:45 -0700 | [diff] [blame] | 70 | |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 71 | As 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 Johnson | eca0338 | 2019-10-22 14:47:45 -0700 | [diff] [blame] | 73 | Once 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. |
| 74 | This applies only for those specifications that originated on the Drive. |
| 75 | |
| 76 | |
| 77 | ## Full Design |
| 78 | |
Sam Elliott | 2061d8b | 2020-04-20 19:56:54 +0100 | [diff] [blame] | 79 | As 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 Johnson | eca0338 | 2019-10-22 14:47:45 -0700 | [diff] [blame] | 80 | Following 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 | |
| 84 | Once an IP block is ready, it can be included in the top-level design. |
| 85 | To 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 Wagner | 09402b4 | 2019-11-21 10:09:21 +0000 | [diff] [blame] | 89 | * Ensure that the top level simulation is not adversely affected. |
Scott Johnson | eca0338 | 2019-10-22 14:47:45 -0700 | [diff] [blame] | 90 | * Open a Pull Request with the necessary code changes. |
| 91 | |
| 92 | If it is not clear on how to proceed, feel free to file an issue requesting assistance. |
Eunchan Kim | 1cfc3be | 2021-11-23 23:38:11 +0000 | [diff] [blame] | 93 | |
| 94 | ## Change of Interrupts |
| 95 | |
| 96 | Changing the interrupts of an IP block needs some extra work in addition to the RTL change. |
| 97 | 1. If a DV environment exists, its testbench (`tb.sv`) will need the ports connected. |
| 98 | 1. If the IP block has been instantiated in a top-level, that top-level will need re-generating to include the new ports. |
| 99 | 1. The auto-generated DIFs will need re-generating. |
| 100 | 1. The PLIC test should also be updated. |
| 101 | |
| 102 | Item 1 is reasonably self-explanatory. |
| 103 | The sections below show how to do items 2-4. |
| 104 | |
| 105 | ### Update TOP |
| 106 | |
| 107 | ```console |
| 108 | $ make -C hw top |
| 109 | ``` |
| 110 | |
| 111 | After 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. |
| 112 | This reads the `.hjson` file and updates the interrupt signal and re-generates the PLIC module if needed. |
| 113 | |
| 114 | ### New DIF |
| 115 | |
| 116 | Unfortunately, re-generating TOP does not resolve everything. |
| 117 | If 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 | |
| 123 | The command above updates the DIF (auto-generated part) under `sw/device/lib/dif/`. |
| 124 | |
| 125 | If DIF for the IP block already uses the interrupt enums inside, you need to manually revise the reference. |
| 126 | In 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`). |
| 127 | For example, `kDifSpiDeviceIrqRxFull`. |
| 128 | To 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. |
| 129 | For example, `kTopEarlgreyPlicIrqIdSpiDeviceRxFull`. |
| 130 | |
| 131 | ### PLIC Unittest |
| 132 | |
| 133 | If the number of interrupts has changed, you need to revise the SW unit test manually. |
| 134 | |
| 135 | Open `sw/device/lib/dif/dif_rv_plic_unittest.cc` and change the `RV_PLIC_PARAM_NUM_SRC` macro to the current interrupt number. |
| 136 | Then, 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. |