opentitan icon indicating copy to clipboard operation
opentitan copied to clipboard

[reg, rtl] create field and csr arrays in uvm reg module, rtl IOs in parameterized modules

Open sriyerg opened this issue 7 years ago • 10 comments

TL; DR; This affects parameterized modules that create variable number of csrs, fields and RTL IOs - example: rv_timer. Having arrayed implementations of IOs / CSRs / FIELDS will be a lot beneficial for DV.

Taking rv_timer as an example: It has 2 parameters - number of timers and number of harts per timer. At this point, the number of timers and harts is fixed to 1 each. In future, this may increase based on need.

The RTL creates individual IOs corresponding to each timer / hart. Example: rv_timer output port - intr_timer_expired_0_0. As the parameter values changes, more individual IOs will be created. It will be beneficial for DV to make this an array instead. Sure, we can create the array in our testbench and use that to do our checks, however the onus still is on the DV engineer to make the change in the testbench when more such IOs are added in RTL. Had the RTL output been an array instead, NO change will be required to be made in DV and all testing will automatically adjust to the new parameter values. Designer can simply change the parameter value and run DV regression suite to confirm no breakage and wouldn't need to involve DV at all.

This problem extends to the reg hjson as well. We have rv_timer template hjson which is converted to the actual hjson that meets the current parameter value requirements (num timers = 1, num harts = 1).

The generated hjson is problematic for our DV field abstraction, which looks like this:

    { multireg: {
        name: "CTRL",
        desc: "Control register",
        count: 1,
        cname: "TIMER",
        swaccess: "rw",
        hwaccess: "hro",
        fields: [
          { bits: "0", name: "active", desc: "If 1, timer operates" }
        ],
      }
    },

This ends up creating a fixed field abstraction called 'active0' in the ctrl register abstraction. This is problematic for DV since it is not scalable. When num timers parameter increases, this will result in additional fields 'active1', 'active2' and so on. This makes it hard to write a generic DV code to target a particular timer, since the field model objects are unique for each timer instance. We will end up having to write an if-else loop to check the timer value and then set that particular field (or do a string based field search within the register for all accesses, which ends up being compute intensive and may slow down the simulation):

function enable_timer(int timer);
  if (timer == 0)         ral.ctrl.active0.set(1'b1);
  else if (timer == 1)  ral.ctrl.active1.set(1'b1);
  ...

  OR
  uvm_reg_field fld = ral.ctrl.get_field_by_name($sformatf("active%0d", timer));
  fld.set(1'b1);
  ...
endfunction

The field 'active' should instead be a bit vector [NUM_TIMERS-1:0], which will make our code much simpler:

function enable_timer(int timer);
  wdata = ral.ctrl.active.get(); // get previous value written
  wdata |= 1 << timer;
  ral.ctrl.active.set(wdata);
  ...
endfunction

The generated hjson is also problematic for the following register abstraction, which looks like this:

    { skipto: "0x100" },
    { name: "CFG0",
      desc: "Configuration for Hart 0",
      swaccess: "rw",
      hwaccess: "hro",
      fields: [
        { bits: "11:0", name: "prescale", desc: "Prescaler to generate tick" },
        { bits: "23:16", name: "step", resval: "0x1", desc: "Incremental value for each tick" },
      ],
    },

This creates a fixed register called 'cfg0' for hart # 0. When the number of harts parameter is increased, this will create additional 'cfg1', cfg2' and so on registers. This is again problematic for DV since it is not scalable. We end up having to do a string based lookup similar to the field example above.

At this point, this is a tiny bench so compute-intensiveness is not an issue. However, it might be a problematic for chip top sims or other larger parameterized IPs we might end up adding in future. Also, the string based lookup to make the DV bench generic is not an elegant solution. It would be worthwhile to invest in a better solution to this problem - perhaps enhance the reg hjson semantics to support such parameterized implementations natively, such that it creates arrayed implementations of csr and field abstractions for DV.

Thanks Sri

sriyerg avatar Jun 01 '19 03:06 sriyerg

I agree with it. Having a way to define register modules parameterized is quite beneficial. But generating the html doc may cause problems. We might end-up to generated based on the top configuration if we go forward to have parameterized register blocks.

I remember the datasheet from Synopsys also has some similar concept in their IPs. If a register is dependent on the parameter, it uses an alphabet letter to show the offset following the register. It makes quite hard to understand but if we generate the combined top-level register docs for IPs, we could show exact address in the doc too.

eunchan avatar Jul 02 '19 22:07 eunchan

As far as I understand, the need for regenerating the regfile and all other artifacts (like html) is not so much of an issue here, but the actual way of how you plumb it in SV (no matter whether in DV or RTL) is a bit cumbersome for parametric registers at the moment.

It looks like part of this issue could already be solved by having the regfile generator output multiregs as a single packed datastructure whose name is the multireg basename, instead of creating new structs for each multireg word.

This solution is already partly there: a multireg is output as a packed struct with subfields, which means that you can access the multireg content by indexing instead of using its subfield names. However, if the combined width of the subfields surpasses the register width, this currently creates separate and differently named structs for each multireg word, which kind of impedes this solution.

Let me explain what I mean using an example from the alert_handler regfile wrapper. I have a templated part that basically stacks subfields of a multireg:

  assign reg2hw_wrap.alert_en = { reg2hw.alert_en.en_a3.q,
                                  reg2hw.alert_en.en_a2.q,
                                  reg2hw.alert_en.en_a1.q,
                                  reg2hw.alert_en.en_a0.q };

As long as the number of enables is below 32 bit, I could also write this as

  assign reg2hw_wrap.alert_en = reg2hw.alert_en[0:3];

I just need to account for the fact that multiregs are currently stacked big endian.

Now, if the number of alerts is greater than 32 (say 64), this is not possible anymore, since the multireg fields are distributed across two register structs named alert_en0 and alert_en1. However, it would be possible if the multireg were still output as a single packed struct alert_en, even if it comprised several words. We would not have to change the html output, just the datastructure splitting of multiregs...

Does this make sense :)?

msfschaffner avatar Sep 24 '19 21:09 msfschaffner

Hey Michael, If I understand you correctly, I think you're basically suggesting for multireg to nest the expanded registers under the base set, so that we can both index by field and also directly manipulate like a giant vector correct?

So for example if today it is alert_en0.field.q

It would become alert_en.reg0.field.q? Or were you not thinking about having the reg(N) portion?

I guess this would remove the need for some of your rewrapping in alert handler?

Thanks Tim

On Tue, Sep 24, 2019, 14:06 msfschaffner [email protected] wrote:

As far as I understand, the need for regenerating the regfile and all other artifacts (like html) is not so much of an issue here, but the actual way of how you plumb it in SV (no matter whether in DV or RTL) is a bit cumbersome for parametric registers at the moment.

It looks like part of this issue could already be solved by having the regfile generator output multiregs as a single packed datastructure whose name is the multireg basename, instead of creating new structs for each multireg word.

This solution is already partly there: a multireg is output as a packed struct with subfields, which means that you can access the multireg content by indexing instead of using its subfield names. However, if the combined width of the subfields surpasses the register width, this currently creates separate and differently named structs for each multireg word, which kind of impedes this solution.

Let me explain what I mean using an example from the alert_handler regfile wrapper. I have a templated part that basically stacks subfields of a multireg:

assign reg2hw_wrap.alert_en = { reg2hw.alert_en.en_a3.q, reg2hw.alert_en.en_a2.q, reg2hw.alert_en.en_a1.q, reg2hw.alert_en.en_a0.q };

As long as the number of enables is below 32 bit, I could also write this as

assign reg2hw_wrap.alert_en = reg2hw.alert_en[0:3];

I just need to account for the fact that multiregs are currently stacked big endian.

Now, if the number of alerts is greater than 32 (say 64), this is not possible anymore, since the multireg fields are distributed across two register structs named alert_en0 and alert_en1. However, it would be possible if the multireg were still output as a single packed struct alert_en, even if it comprised several words. We would not have to change the html output, just the datastructure splitting of multiregs...

Does this make sense :)?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/lowRISC/opentitan/issues/47?email_source=notifications&email_token=AAH2RSRT4XSZTWRYNCNSCZ3QLJ6M5A5CNFSM4ISTJVA2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7PZYTI#issuecomment-534748237, or mute the thread https://github.com/notifications/unsubscribe-auth/AAH2RSS6R7YRTMTOE6IFFRLQLJ6M5ANCNFSM4ISTJVAQ .

tjaychen avatar Sep 25 '19 05:09 tjaychen

Yes exactly, but I would just keep the basename without any index. I.e., a multireg is currently already partially nested as ipname.multiregbase<idx0>.field<idx1>.q. By partially I mean that we always group them according to the register layout and pack 32 bits into one nesting level. What I am suggesting is to just use "multiregbase", and nest all fields under that name. The fields are still uniquely enumerated up to whatever the maximum is.

It is not pretty, and the indexing is a bit awkward since fields are stacked big endian, but at least we could plumb it in SV without templating. I still need to check the code, but I believe it could be a good intermediate workaround until Eunchan's overhaul of reggen/topgen (#30) is implemented.

msfschaffner avatar Sep 25 '19 15:09 msfschaffner

Eunchan can correct me..but i thought one of the primary issues we ran into was that we could not "instantiate" a package with parameters passed in. So even if we do this, would we remove the need to template the existing pkg modules? @eunchan did I remember this correctly?

On Wed, Sep 25, 2019 at 8:22 AM msfschaffner [email protected] wrote:

Yes exactly, but I would just keep the basename without any index. I.e., a multireg is currently already partially nested as ipname.multiregbase.field.q. By partially I mean that we always group them according to the register layout and pack 32 bits into one nesting level. What I am suggesting is to just use "multiregbase", and nest all fields under that name. The fields are still uniquely enumerated up to whatever the maximum is.

It is not pretty, and the indexing is a bit awkward since fields are stacked big endian, but at least we could plumb it in SV without templating. I still need to check the code, but I believe it could be a good intermediate workaround until Eunchan's overhaul of reggen/topgen ( #30 https://github.com/lowRISC/opentitan/issues/30) is implemented.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/lowRISC/opentitan/issues/47?email_source=notifications&email_token=AAH2RSU6NOXD34IGRW77KMTQLN64DA5CNFSM4ISTJVA2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7SJSGQ#issuecomment-535075098, or mute the thread https://github.com/notifications/unsubscribe-auth/AAH2RSSSSJPFERYW7VQ4FLTQLN64DANCNFSM4ISTJVAQ .

tjaychen avatar Sep 25 '19 17:09 tjaychen

Your understanding is correct. The case we concerned was the case of multiple instances of the same IP but defined with different parameters.

Please remind that cannot be solved currently. Using package for register structure, we only can have single set of the register structure. So, Michael's thought can be applied here as it doens't go backward.

Eventually, we should liberate from register package and go for parameterized interface.

On Wed, Sep 25, 2019 at 10:32:39AM -0700, tjaychen wrote:

Eunchan can correct me..but i thought one of the primary issues we ran into was that we could not "instantiate" a package with parameters passed in. So even if we do this, would we remove the need to template the existing pkg modules? @eunchan did I remember this correctly?

On Wed, Sep 25, 2019 at 8:22 AM msfschaffner [email protected] wrote:

Yes exactly, but I would just keep the basename without any index. I.e., a multireg is currently already partially nested as ipname.multiregbase.field.q. By partially I mean that we always group them according to the register layout and pack 32 bits into one nesting level. What I am suggesting is to just use "multiregbase", and nest all fields under that name. The fields are still uniquely enumerated up to whatever the maximum is.

It is not pretty, and the indexing is a bit awkward since fields are stacked big endian, but at least we could plumb it in SV without templating. I still need to check the code, but I believe it could be a good intermediate workaround until Eunchan's overhaul of reggen/topgen ( #30 https://github.com/lowRISC/opentitan/issues/30) is implemented.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/lowRISC/opentitan/issues/47?email_source=notifications&email_token=AAH2RSU6NOXD34IGRW77KMTQLN64DA5CNFSM4ISTJVA2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7SJSGQ#issuecomment-535075098, or mute the thread https://github.com/notifications/unsubscribe-auth/AAH2RSSSSJPFERYW7VQ4FLTQLN64DANCNFSM4ISTJVAQ .

-- You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub: https://github.com/lowRISC/opentitan/issues/47#issuecomment-535129119

eunchan avatar Sep 25 '19 17:09 eunchan

Yeah, it is only a partial solution and we would still have to generate the package using the template flow. But we could avoid having to write additional templated breakout wrappers to plug the registers into RTL.

msfschaffner avatar Sep 25 '19 18:09 msfschaffner

@eunchan or @msfschaffner has the status on this been refreshed based upon current multireg thinking?

sjgitty avatar Jan 03 '20 19:01 sjgitty

I think this could still be very beneficial for DV, and given that we have to update the FPV and DOC backends, it probably makes sense to rework the DV backend as well.

Let's revisit this once we have an initial working RTL prototype (on an integration branch, as @eunchan suggested). I think the new multireg structure should be compatible with what @sriyerg had in mind here...

msfschaffner avatar Jan 03 '20 19:01 msfschaffner

already supported multi-reg/field in RAL mode. Closing this

weicaiyang avatar Jul 11 '22 22:07 weicaiyang