Skip to content
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

When Should QEMU CPU Call Specific Access Functions of QemuInitiatorSocket? #15

Open
alpha-beta-user opened this issue Dec 18, 2024 · 3 comments

Comments

@alpha-beta-user
Copy link

alpha-beta-user commented Dec 18, 2024

This is a handsome work!

I know that qemu_arm_cpu has a member called socket, which is mainly used for external memory access. The type of this socket is QemuInitiatorSocket. This socket has three access functions, as shown in the code below. I also understand that these three functions are essential for the socket.
The code below is in router.h file
target_socket.register_b_transport(this, &router::b_transport); target_socket.register_transport_dbg(this, &router::transport_dbg); target_socket.register_get_direct_mem_ptr(this, &router::get_direct_mem_ptr);

I would like to ask: at what point should the QEMU CPU call each of these functions? when to call dmi access--get_direct_mem_ptr (which seems create a memory region) ? and when to call just b_transport function?

thanks for your attention.

@markfoodyburton
Copy link
Contributor

In general, I suggest reading up on SystemC TLM-2.0 as these functions are part of the TLM 2.0 (IEEE 1666) standard.
1/ b_transport is called for MMIO accesses (and initial memory accesses)
2/ dbg_transport is called for debugger accesses
3/ get_direct_mem_ptr is called if the SystemC model provides a DMI hint, e.g. when memory is accessed, at which point the underlying host memory will be mapped directly into QEMU.

Hope that helps

@alpha-beta-user
Copy link
Author

thanks for your quick answer.

I would like to know if a SystemC module provides two access methods simultaneously, namely the DMI access method and the b_transport method, will the CPU prioritize using the DMI access method? In other words, is there a priority for access methods?

I observed that the CPU first calls the transport method to verify the address validity. Then, it checks whether the SystemC module includes the DMI access method. If it does, the CPU prioritizes using the DMI access method and creates the corresponding memory region for direct access by the CPU.

@alpha-beta-user
Copy link
Author

alpha-beta-user commented Dec 19, 2024

In the first call b_transport process, the systemc module can set the trans if it can be dmi_enable. If it is true, cpu will call get_mem_ptr func to access the memory directly.

`void do_regular_access(TlmPayload& trans)
{
using sc_core::sc_time;

    uint64_t addr = trans.get_address();
    sc_time now = m_initiator.initiator_get_local_time();

    m_inst.get().unlock_iothread();
    m_on_sysc.run_on_sysc([this, &trans, &now] { (*this)->b_transport(trans, now); });
    m_inst.get().lock_iothread();
    /*
     * Reset transaction address before dmi check (could be altered by
     * b_transport).
     */
    trans.set_address(addr);
    check_qemu_mr_hint(trans);
    if (trans.is_dmi_allowed()) {
        check_dmi_hint_locked(trans);
    }

    m_initiator.initiator_set_local_time(now);
}`

Is my undstanding right?

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

No branches or pull requests

2 participants