GithubHelp home page GithubHelp logo

Comments (5)

Popebl avatar Popebl commented on August 23, 2024 1

I found the following description in Section 3.9, 'Top External Interrupt CSRs,' of the RISC-V Advanced Interrupt Architecture Version 1.0, revised on June 30, 2023.

A read of a *topei CSR returns zero either if no interrupt is both pending in the interrupt file’s eip
array and enabled in its eie array, or if eithreshold is not zero and no pending-and-enabled interrupt
has an identity number less than the value of eithreshold. Otherwise, the value returned from a read
of *topei has this format:

It is almost always a mistake to write to a *topei CSR without a simultaneous read to
learn which interrupt was claimed. 

So, I believe the scrrw instruction is used to read and claim the highest-priority pending-and-enabled interrupt, and topei will not be written to zero, but will change to indicate the next highest-priority pending-and-enabled interrupt.

Is my understanding correct?

from opensbi.

mikey avatar mikey commented on August 23, 2024

I don't think it's necessary. You can just return from the interrupt but if there is another pending you'll just take an interrupt again. So you may as well process all that are available and avoid the extra privilege switch.

Linux does the same thing with stopi.
https://github.com/torvalds/linux/blob/master/drivers/irqchip/irq-riscv-intc.c#L41

from opensbi.

Popebl avatar Popebl commented on August 23, 2024

What confuses me the most is the behavior of TOPEI and STOPEI after executing csrrw rd, mtopei/stopei, x0. It seems that mtopei/stopei will be set to 0. Is the while loop used to handle interrupts that occur during the ISR process?

from opensbi.

mikey avatar mikey commented on August 23, 2024

What confuses me the most is the behavior of TOPEI and STOPEI after executing csrrw rd, mtopei/stopei, x0. It seems that mtopei/stopei will be set to 0.

The write is ignored. This is what the spec says:

A write to a *topei CSR claims the reported interrupt identity by clearing its pending bit in the interrupt file. The value written is ignored; rather, the current readable value of the register determines which interrupt-pending bit is cleared.

Is the while loop used to handle interrupts that occur during the ISR process?

Yes.

from opensbi.

Popebl avatar Popebl commented on August 23, 2024

I am examining the function of TOPEI in QEMU. The read-modify-write operation on TOPEI involves two steps: first, it reads the highest-priority pending-and-enabled interrupt, and second, it writes an ignore value to clear the top pending interrupt. Therefore, on the second access, TOPEI should report the next highest-priority pending-and-enabled interrupt.

https://github.com/qemu/qemu/blob/master/hw/intc/riscv_imsic.c#L112

static int riscv_imsic_topei_rmw(RISCVIMSICState *imsic, uint32_t page,
                                 target_ulong *val, target_ulong new_val,
                                 target_ulong wr_mask)
{
    uint32_t base, topei = riscv_imsic_topei(imsic, page);

    /* Read pending and enabled interrupt with highest priority */
    if (val) {
        *val = topei;
    }
    /* Writes ignore value and clear top pending interrupt */
    if (topei && wr_mask) {
        topei >>= IMSIC_TOPEI_IID_SHIFT;
        base = page * imsic->num_irqs;
        if (topei) {
            imsic->eistate[base + topei] &= ~IMSIC_EISTATE_PENDING;
        }

        riscv_imsic_update(imsic, page);
    }

    return 0;
}

Thanks very much with best regards!

from opensbi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.