diff --git a/kernel/drivers/opensbi/extensions/ipi.cpp b/kernel/drivers/opensbi/extensions/ipi.cpp index 748aa11..d568db5 100644 --- a/kernel/drivers/opensbi/extensions/ipi.cpp +++ b/kernel/drivers/opensbi/extensions/ipi.cpp @@ -13,14 +13,12 @@ namespace opensbi::ipi { }; } - SbiRet send_ipi( - unsigned long hart_mask, - unsigned long hart_mask_base) { + SbiRet send_ipi(HartMask hart_mask) { return ecall( static_cast(ExtensionId::IPI), static_cast(FunctionId::SEND_IPI), - hart_mask, - hart_mask_base); + hart_mask.mask, + hart_mask.base); } } // End namespace opensbi::ipi diff --git a/kernel/drivers/opensbi/extensions/rfence.cpp b/kernel/drivers/opensbi/extensions/rfence.cpp new file mode 100644 index 0000000..b60f7bf --- /dev/null +++ b/kernel/drivers/opensbi/extensions/rfence.cpp @@ -0,0 +1,116 @@ +#include "opensbi/extensions/rfence.h" + +namespace drivers { +namespace opensbi::rfence { + + namespace { + enum class ExtensionId { + RFENCE = 0x52464E43 + }; + + enum class FunctionId { + REMOTE_FENCE_I, + REMOTE_SFENCE_VMA, + REMOTE_SFENCE_VMA_ASID, + REMOTE_HFENCE_GVMA_VMID, + REMOTE_HFENCE_GVMA, + REMOTE_HFENCE_VVMA_ASID, + REMOTE_HFENCE_VVMA + }; + } + + SbiRet remote_fence_i(HartMask hart_mask) { + return ecall( + static_cast(ExtensionId::RFENCE), + static_cast(FunctionId::REMOTE_FENCE_I), + hart_mask.mask, + hart_mask.base); + } + + SbiRet remote_sfence_vma( + HartMask hart_mask, + unsigned long start_addr, + unsigned long size) { + return ecall( + static_cast(ExtensionId::RFENCE), + static_cast(FunctionId::REMOTE_SFENCE_VMA), + hart_mask.mask, + hart_mask.base, + start_addr, + size); + } + + SbiRet remote_sfence_vma_asid( + HartMask hart_mask, + unsigned long start_addr, + unsigned long size, + unsigned long asid) { + return ecall( + static_cast(ExtensionId::RFENCE), + static_cast(FunctionId::REMOTE_SFENCE_VMA_ASID), + hart_mask.mask, + hart_mask.base, + start_addr, + size, + asid); + } + + SbiRet remote_hfence_gvma_vmid( + HartMask hart_mask, + unsigned long start_addr, + unsigned long size, + unsigned long vmid) { + return ecall( + static_cast(ExtensionId::RFENCE), + static_cast(FunctionId::REMOTE_HFENCE_GVMA_VMID), + hart_mask.mask, + hart_mask.base, + start_addr, + size, + vmid); + } + + SbiRet remote_hfence_gvma( + HartMask hart_mask, + unsigned long start_addr, + unsigned long size) { + return ecall( + static_cast(ExtensionId::RFENCE), + static_cast(FunctionId::REMOTE_HFENCE_GVMA), + hart_mask.mask, + hart_mask.base, + start_addr, + size); + } + + SbiRet remote_hfence_vvma_asid( + HartMask hart_mask, + unsigned long start_addr, + unsigned long size, + unsigned long asid) { + return ecall( + static_cast(ExtensionId::RFENCE), + static_cast(FunctionId::REMOTE_HFENCE_VVMA_ASID), + hart_mask.mask, + hart_mask.base, + start_addr, + size, + asid); + } + + SbiRet remote_hfence_vvma( + HartMask hart_mask, + unsigned long start_addr, + unsigned long size) { + return ecall( + static_cast(ExtensionId::RFENCE), + static_cast(FunctionId::REMOTE_HFENCE_VVMA), + hart_mask.mask, + hart_mask.base, + start_addr, + size); + } + +} // End namespace opensbi::rfence +} // End namespace drivers + diff --git a/kernel/drivers/opensbi/include/opensbi/extensions/ipi.h b/kernel/drivers/opensbi/include/opensbi/extensions/ipi.h index 1060a29..86cd01a 100644 --- a/kernel/drivers/opensbi/include/opensbi/extensions/ipi.h +++ b/kernel/drivers/opensbi/include/opensbi/extensions/ipi.h @@ -5,9 +5,7 @@ namespace drivers { namespace opensbi::ipi { - SbiRet send_ipi( - unsigned long hart_mask, - unsigned long hart_mask_base); + SbiRet send_ipi(HartMask hart_mask); } // End namespace opensbi::ipi } // End namespace drivers diff --git a/kernel/drivers/opensbi/include/opensbi/extensions/rfence.h b/kernel/drivers/opensbi/include/opensbi/extensions/rfence.h new file mode 100644 index 0000000..0e5904a --- /dev/null +++ b/kernel/drivers/opensbi/include/opensbi/extensions/rfence.h @@ -0,0 +1,44 @@ +#pragma once + +#include "opensbi/opensbi.h" + +namespace drivers { +namespace opensbi::rfence { + + SbiRet remote_fence_i(HartMask hart_mask); + + SbiRet remote_sfence_vma( + HartMask hart_mask, + unsigned long start_addr, + unsigned long size); + + SbiRet remote_sfence_vma_asid( + HartMask hart_mask, + unsigned long start_addr, + unsigned long size, + unsigned long asid); + + SbiRet remote_hfence_gvma_vmid( + HartMask hart_mask, + unsigned long start_addr, + unsigned long size, + unsigned long vmid); + + SbiRet remote_hfence_gvma( + HartMask hart_mask, + unsigned long start_addr, + unsigned long size); + + SbiRet remote_hfence_vvma_asid( + HartMask hart_mask, + unsigned long start_addr, + unsigned long size, + unsigned long asid); + + SbiRet remote_hfence_vvma( + HartMask hart_mask, + unsigned long start_addr, + unsigned long size); + +} // End namespace opensbi::rfence +} // End namespace drivers diff --git a/kernel/drivers/opensbi/include/opensbi/opensbi.h b/kernel/drivers/opensbi/include/opensbi/opensbi.h index 14a1583..c23b9a5 100644 --- a/kernel/drivers/opensbi/include/opensbi/opensbi.h +++ b/kernel/drivers/opensbi/include/opensbi/opensbi.h @@ -8,6 +8,11 @@ namespace opensbi { typedef unsigned long sbiword_t; typedef const unsigned long * hart_mask_t; + struct HartMask { + unsigned long mask; + unsigned long base; + }; + struct SbiRet { sbiword_t error; sbiword_t value; diff --git a/kernel/drivers/opensbi/meson.build b/kernel/drivers/opensbi/meson.build index 9f67dd8..c01bed1 100644 --- a/kernel/drivers/opensbi/meson.build +++ b/kernel/drivers/opensbi/meson.build @@ -4,7 +4,8 @@ kernel_sources += [ 'extensions/legacy.cpp', 'extensions/base.cpp', 'extensions/timer.cpp', - 'extensions/ipi.cpp' + 'extensions/ipi.cpp', + 'extensions/rfence.cpp' ), ]