Skip to content

Add H csr vsip,hgeie,hideleg,hie,hip,hvip,vsie,vsscratch,hgeip #617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Shehrozkashif
Copy link
Collaborator

@Shehrozkashif Shehrozkashif commented Apr 16, 2025

This pr includes csr vsip,hegeie,hideleg,hie,hip,hvip,vsie,vsscratch,hgeip

@ThinkOpenly ThinkOpenly changed the title Add H csr vsip,hegeie,hideleg,hie,hip,hvip,vsie,vsscratch,hgeip Add H csr vsip,hgeie,hideleg,hie,hip,hvip,vsie,vsscratch,hgeip Apr 16, 2025
Copy link
Collaborator

@ThinkOpenly ThinkOpenly left a comment

Choose a reason for hiding this comment

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

I did not finish the review, but thought this feedback would be helpful for now.

Comment on lines 8 to 10
The `hgeie` register is an HSXLEN-bit read/write register that contains enable bits
for the guest external interrupts at this hart. Each bit in `hgeie` corresponds to
a guest external interrupt and determines whether that interrupt is enabled.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hew to the text in the spec:

The hgeie register is an HSXLEN-bit read/write register that contains enable bits for the guest external interrupts at this hart. Guest external interrupt number i corresponds with bit i in hgeie.

Guest external interrupts represent interrupts directed to individual virtual machines at VS-level. If a RISC-V platform supports placing a physical device under the direct control of a guest OS with minimal hypervisor intervention (known as pass-through or direct assignment between a virtual machine and the physical device), then, in such circumstance, interrupts from the device are intended for a specific virtual machine.

[Note]
Support for guest external interrupts requires an interrupt controller that can collect virtual-machine-directed interrupts separately from other interrupts.

The number of bits implemented in hgeie for guest external interrupts is UNSPECIFIED and may be zero. This number is known as GEILEN. The least-significant bits are implemented first, apart from bit 0. Hence, if GEILEN is nonzero, bits GEILEN:1 shall be writable in hgeie, and all other bit positions shall be read-only zeros.

Register hgeie selects the subset of guest external interrupts that cause a supervisor-level (HS-level) guest external interrupt. The enable bits in hgeie do not affect the VS-level external interrupt signal selected from hgeip by hstatus.VGEIN.

(I culled content that was specific to hgeip or seems to be specific to the extension, not hgeie itself.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Got it, I’ll fix it to be more like the spec.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Restore backticks around all the CSRs in all the description fields.

If you could make these LONG lines shorter (less than about 70-80 characters), that is preferred.

length: SXLEN
fields:
SGEIE:
location: 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

12

to VS-mode based on the `hgeie` setting.

VSEIE:
location: 4
Copy link
Collaborator

Choose a reason for hiding this comment

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

10

to be processed based on the configuration in `hvip` and other platform-specific sources.

VSTIE:
location: 8
Copy link
Collaborator

Choose a reason for hiding this comment

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

6

VS-level timer interrupt enable bit. When set, allows VS-level timer interrupts to be processed
based on the `hvip` configuration and any platform-specific timer interrupts.

VSSIE:
Copy link
Collaborator

Choose a reason for hiding this comment

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

2

Pending interrupt bit for VS-level external interrupts. This bit is writable and
is set to 1 to assert a VS-level external interrupt.

VSTIP:
Copy link
Collaborator

Choose a reason for hiding this comment

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

6

is set to 1 to assert a VS-level timer interrupt.

VSSIP:
location: 5
Copy link
Collaborator

Choose a reason for hiding this comment

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

2

Pending interrupt bit for VS-level software interrupts. This bit is writable and
is set to 1 to assert a VS-level software interrupt.

reserved_6_15:
Copy link
Collaborator

Choose a reason for hiding this comment

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

just "reserved"
(I'm not sure this is the preferred way of noting always-zero bits, but we'll roll with it for now...)

Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't need to list reserved bits at all. If there is no field at a bit, it is assumed to be reserved

is set to 1 to assert a VS-level software interrupt.

reserved_6_15:
location: 6
Copy link
Collaborator

Choose a reason for hiding this comment

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

"15-11,9-7,5-3,1-0"

Comment on lines 15 to 19
The standard portion (bits 15:0) of vsie is formatted as follows:
15 14 13 12 10 9 8 6 5 4 2 1 0
0 LCOFIE 0 SEIE 0 STIE 0 SSIE 0
2 1 3 1 3 1 3 1 1

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is obviously not formatted well. Delete it. The fields information below covers the same information.

Copy link
Collaborator

@dhower-qc dhower-qc left a comment

Choose a reason for hiding this comment

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

This is a complicated set of CSRs. I've added a bunch of comments, but note that we're likely to need multiple review passes before it's ready.

Comment on lines +7 to +17
description: |
The hgeie register is an HSXLEN-bit read/write register that contains enable bits for the guest external interrupts at this hart. Guest external interrupt number i corresponds with bit i in hgeie.

Guest external interrupts represent interrupts directed to individual virtual machines at VS-level. If a RISC-V platform supports placing a physical device under the direct control of a guest OS with minimal hypervisor intervention (known as pass-through or direct assignment between a virtual machine and the physical device), then, in such circumstance, interrupts from the device are intended for a specific virtual machine.

[Note]
Support for guest external interrupts requires an interrupt controller that can collect virtual-machine-directed interrupts separately from other interrupts.

The number of bits implemented in hgeie for guest external interrupts is UNSPECIFIED and may be zero. This number is known as GEILEN. The least-significant bits are implemented first, apart from bit 0. Hence, if GEILEN is nonzero, bits GEILEN:1 shall be writable in hgeie, and all other bit positions shall be read-only zeros.

Register hgeie selects the subset of guest external interrupts that cause a supervisor-level (HS-level) guest external interrupt. The enable bits in hgeie do not affect the VS-level external interrupt signal selected from hgeip by hstatus.VGEIN.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's change this to the new structured description. Should look like:

description:
  - id: csr-hgeie-purpose
    normative: true
    text: |
      The hgeie register is an HSXLEN-bit read/write register that contains enable bits for the guest external interrupts at this hart.
  - id: csr-hgeie-bits
    normative: true
    text: Guest external interrupt number i corresponds with bit i in hgeie.
  - id: csr-hgeie-interrupts
    normative: true
    text: |
      Guest external interrupts represent interrupts directed to individual virtual machines
      at VS-level.
      If a RISC-V platform supports placing a physical device under the direct control of a
      guest OS with minimal hypervisor intervention (known as pass-through or direct assignment
      between a virtual machine and the physical device), then, in such circumstance,
      interrupts from the device are intended for a specific virtual machine.
  - id: csr-hgeie-controller-req
    normative: false
    text: |
      Support for guest external interrupts requires an interrupt controller that can collect
      virtual-machine-directed interrupts separately from other interrupts.
  - id: csr-hgeie-geilen
    normative: true
    text: |
      The number of bits implemented in hgeie for guest external interrupts is UNSPECIFIED and
      may be zero.
      This number is known as `GEILEN`.
  - id: csr-hgeie-bitorder
    normative: true
    text: |
      The least-significant bits are implemented first, apart from bit 0.
  - id: csr-hgeie-nonzero-geilen
    normative: true
    text: |
      Hence, if GEILEN is nonzero, bits `GEILEN`:1 shall be writable in hgeie, and all other
      bit positions shall be read-only zeros.
  - id: csr-hgeie-select
    normative: true
    text: |
      Register hgeie selects the subset of guest external interrupts that cause a
      supervisor-level (HS-level) guest external interrupt.
  - id: csr-hgeie-hgeip
    normative: true
    text: |
      The enable bits in hgeie do not affect the VS-level external interrupt signal selected
      from hgeip by hstatus.VGEIN.

We should do this for all the descriptiong in the PR.

location_rv32: 31-1
location_rv64: 63-1
type: RW
reset_value: 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

UNDEFINED_LEGAL

definedBy: H
length: SXLEN
fields:
GEI_ENABLE:
Copy link
Collaborator

Choose a reason for hiding this comment

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

add:

  long_name: Guest external interrupt enable bits

Comment on lines +28 to +30
description: |
The number of bits implemented in hgeie for guest external interrupts is UNSPECIFIED and may be zero. This number is known as GEILEN. The least-significant bits are implemented first, apart from bit 0. Hence, if GEILEN is nonzero, bits GEILEN:1 shall be writable in hgeie, and all other bit positions shall be read-only zeros in hgeie.
Register hgeie selects the subset of guest external interrupts that cause a supervisor-level (HS-level) guest external interrupt. The enable bits in hgeie do not affect the VS-level external interrupt signal selected from hgeip by hstatus.VGEIN.
Copy link
Collaborator

Choose a reason for hiding this comment

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

The description here is already stated in the description of the CSR overall. For this field, I would just say "Enable bits; see description of hgeie".

GEI_ENABLE:
location_rv32: 31-1
location_rv64: 63-1
type: RW
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since this field is WARL, the type is configuration-dependent; it's read-only if GEILEN is zero, and read/write otherwise. As a complication, UDB has encoded GEILEN as NUM_EXTERNAL_GUEST_INTERRUPTS.

  type(): return NUM_EXTERNAL_GUEST_INTERRUPTS > 0 ? CsrFieldType::RW : CsrFieldType::RO;


VSTIP:
location: 6
type: RO
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be RO-H


VSSIP:
location: 2
type: RO
Copy link
Collaborator

Choose a reason for hiding this comment

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

RW

This bit is the logical OR of `vstip` from `hvip` and any other timer interrupt directed to VS-level.

VSSIP:
location: 2
Copy link
Collaborator

Choose a reason for hiding this comment

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

  alias: hvip.VSSIP
  sw_write(csr_value): CSR[hvip].VSSIP = csr_value.VSSIP;

Comment on lines +32 to +38
VSTIP:
location: 6
type: RO
reset_value: 0
description: |
Pending interrupt bit for VS-level timer interrupts (VSTI).
This bit is the logical OR of `vstip` from `hvip` and any other timer interrupt directed to VS-level.
Copy link
Collaborator

Choose a reason for hiding this comment

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

[[[ NOTE: I wrote this before I realized we haven't added any Sstc CSRs yet. Can you also add them so that this doesn't fall through the cracks? ]]]

VSTIP is altered by the Sstc extension.

19.2.2. Hypervisor Interrupt (hvip, hip, and hie) Registers
This extension modifies the description of the VSTIP/VSTIE bits in the hip/hie registers as follows:

Bits hip.VSTIP and hie.VSTIE are the interrupt-pending and interrupt-enable bits for VS-level timer interrupts. VSTIP is read-only in hip, and is the logical-OR of hvip.VSTIP and the timer interrupt signal resulting from vstimecmp (if vstimecmp is implemented). The hip.VSTIP bit, in response to timer interrupts generated by vstimecmp, is set and cleared by writing vstimecmp with a value that respectively is less than or equal to, or greater than, the current (time + htimedelta) value. The hip.VSTIP bit remains defined while V=0 as well as V=1.

This will require the function form of reset_value() on the field.

It will also require a sw_read() function for the CSR overall. Something like:

  sw_read(): |
    Bits<7> vstip_bit = 0;
    if (implemented?(ExtensionName::Sstc)) {
      if ((CSR[hvip].VSTIP == 1) | (CSR[vstimecmp].VALUE > (read_mtime() + CSR[htimedelta].DELTA)) {
        vstip_bit = 7'b1000000;
      }
    }

    Bits<3> vssip_bit = CSR[hvip].VSSIP == 0 ? 0 : 3'b100;
    # ...

    return lcofi_bit | sgeip_bit | vseip_bit | vstip_bit | vssip_bit;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sure ill add Sstc CSRs I believe these are they ?

  1. "Sstc" Extension for Supervisor-mode Timer Interrupts, Version 1.0.0 123
    16.1. Machine and Supervisor Level Additions 123
    16.1.1. Supervisor Timer Register (stimecmp) 123
    16.1.2. Machine Interrupt Registers (mip and mie) 124
    16.1.3. Supervisor Interrupt Registers (sip and sie) 124
    16.1.4. Machine Counter-Enable Register (mcounteren) 124
    16.2. Hypervisor Extension Additions 124
    16.2.1. Virtual Supervisor Timer Register (vstimecmp) 124
    16.2.2. Hypervisor Interrupt Registers (hvip, hip, and hie) 125
    16.2.3. Hypervisor Counter-Enable Register (hcounteren) 125
    16.3. Environment Config (menvcfg/henvcfg) Support

@@ -0,0 +1,46 @@
# yaml-language-server: $schema=../../../schemas/csr_schema.json
Copy link
Collaborator

Choose a reason for hiding this comment

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

This CSR needs a sw_read function that reflects the following (I've started a skeleton of it in the VSSIP comment):

SGEIP is read-only in hip, and is 1 if and only if the bitwise logical-AND of CSRs hgeip and hgeie is nonzero in any bit.

VSEIP is read-only in hip, and is the logical-OR of these interrupt sources:

  • bit VSEIP of hvip;
  • the bit of hgeip selected by hstatus.VGEIN; and
  • any other platform-specific external interrupt signal directed to VS-level.

VSTIP is read-only in hip, and is the logical-OR of hvip.VSTIP and any other platform-specific timer interrupt signal directed to VS-level.

VSSIP in hip is an alias (writable) of the same bit in hvip

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.

3 participants