Rename sbi_domain functions and per-domain data
cover Rename sbi_domain functions and per-domain data
This series changes the names of sbi domain callback functions and per-domain data structures and functions to represent what they actually do. There are no functional changes.
Patch 1 renames the hart protection map_range()/unmap_range() callbacks and their wrappers to temp_map_range()/temp_unmap_range(). These are not generic address-range mapping operations but they are only used by M-mode to get temporarily access to an S/U-mode address range.
Patch 2 renames the per-domain data mechanism to per-domain state. The areas registered through it hold various states associated with a domain - hart context in sbi_domain_context and MPXY state in sbi_mpxy today - which "data" does not convey.
Patch 1 earlier was part of SMMPT series but due to patch 2 making it a separate series and it will be removed from next version of SMMPT series.
https://lore.kernel.org/opensbi/[email protected]/
Rahul Pathak (2):
lib: sbi: Rename map_range/unmap_range functions
lib: sbi_domain: Rename per-domain data to per-domain state
include/sbi/sbi_domain.h | 6 +- include/sbi/sbi_domain_data.h | 93 -------------------- include/sbi/sbi_domain_state.h | 93 ++++++++++++++++++++ include/sbi/sbi_hart_protection.h | 27 +++--- lib/sbi/objects.mk | 2 +- lib/sbi/sbi_dbtr.c | 26 +++--- lib/sbi/sbi_domain.c | 6 +- lib/sbi/sbi_domain_context.c | 14 +-- lib/sbi/sbi_domain_data.c | 138 ------------------------------ lib/sbi/sbi_domain_state.c | 138 ++++++++++++++++++++++++++++++ lib/sbi/sbi_ecall_dbcn.c | 4 +- lib/sbi/sbi_hart_pmp.c | 10 +-- lib/sbi/sbi_hart_protection.c | 12 +-- lib/sbi/sbi_mpxy.c | 56 ++++++------ lib/sbi/sbi_pmu.c | 4 +- lib/sbi/sbi_sse.c | 8 +- 16 files changed, 321 insertions(+), 316 deletions(-) delete mode 100644 include/sbi/sbi_domain_data.h create mode 100644 include/sbi/sbi_domain_state.h delete mode 100644 lib/sbi/sbi_domain_data.c create mode 100644 lib/sbi/sbi_domain_state.c
Signature · 7 lines
2.53.0 -- opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
PATCH 1/2 lib: sbi: Rename map_range/unmap_range functions
*_map_range and *_unmap_range functions are required in M-Mode to get the temporary access to S-Mode and U-Mode regions. Thse functions only operate using the TYPE_MEMORY memory protection mechanisms. Rename them to reflect the actual usage of these functions and let generic map/unmap_range names to implement generic functions
--- include/sbi/sbi_hart_protection.h | 27 ++++++++++++++++----------- lib/sbi/sbi_dbtr.c | 26 +++++++++++++------------- lib/sbi/sbi_ecall_dbcn.c | 4 ++-- lib/sbi/sbi_hart_pmp.c | 10 +++++----- lib/sbi/sbi_hart_protection.c | 12 ++++++------ lib/sbi/sbi_mpxy.c | 24 ++++++++++++------------ lib/sbi/sbi_pmu.c | 4 ++-- lib/sbi/sbi_sse.c | 8 ++++---- 8 files changed, 60 insertions(+), 55 deletions(-)
include/sbi/sbi_hart_protection.h +16 -11
@@ -40,13 +40,17 @@ struct sbi_hart_protection {/** Unconfigure protection for current HART (Optional) */ void (*unconfigure)(struct sbi_scratch *scratch,struct sbi_domain *dom); -/** Create temporary mapping to access address range on current HART (Optional) */ -int (*map_range)(struct sbi_scratch *scratch, -unsigned long base,unsigned long size); - -/** Destroy temporary mapping on current HART (Optional) */ -int (*unmap_range)(struct sbi_scratch *scratch, -unsigned long base,unsigned long size); +/** +* Give temporary M-mode access to an S/U-mode address range on current +* HART (Optional). Only applicable for the TYPE_MEMORY and the TYPE_ID +* mechanisms are not invoked. +*/ +int (*temp_map_range)(struct sbi_scratch *scratch, +unsigned long base,unsigned long size); + +/** Remove the temporary M-mode access on the current HART (Optional) */ +int (*temp_unmap_range)(struct sbi_scratch *scratch, +unsigned long base,unsigned long size); };/**
@@ -111,23 +115,24 @@ int sbi_hart_protection_reconfigure(struct sbi_scratch *scratch, struct sbi_domain *next_dom);/** -* Create temporary mapping to access address range on current HART +* Give temporary M-mode access to an S/U-mode address range on the +* current HART. Only valid for TYPE_MEMORY. * * @param base base address of the temporary mapping * @param size size of the temporary mapping * * @return 0 on success and negative error code on failure */ -int sbi_hart_protection_map_range (unsigned long base,unsigned long size); +int sbi_hart_protection_temp_map_range (unsigned long base,unsigned long size);/** -* Destroy temporary mapping to access address range on current HART +* Remove the temporary M-mode access on the current HART * * @param base base address of the temporary mapping * @param size size of the temporary mapping * * @return 0 on success and negative error code on failure */ -int sbi_hart_protection_unmap_range (unsigned long base,unsigned long size); +int sbi_hart_protection_temp_unmap_range (unsigned long base,unsigned long size);#endif /* __SBI_HART_PROTECTION_H__ */
lib/sbi/sbi_dbtr.c +13 -13
@@ -580,7 +580,7 @@ int sbi_dbtr_read_trig(unsigned long smode, shmem_base =hart_shmem_base (hs); -sbi_hart_protection_map_range ((unsigned long )shmem_base, +sbi_hart_protection_temp_map_range ((unsigned long )shmem_base, trig_count *sizeof (*entry));for_each_trig_entry (shmem_base, trig_count,typeof (*entry), entry) { xmit = &entry->data;
@@ -594,7 +594,7 @@ int sbi_dbtr_read_trig(unsigned long smode, xmit->tdata2 =cpu_to_lle (trig->tdata2); xmit->tdata3 =cpu_to_lle (trig->tdata3); } -sbi_hart_protection_unmap_range ((unsigned long )shmem_base, +sbi_hart_protection_temp_unmap_range ((unsigned long )shmem_base, trig_count *sizeof (*entry));return SBI_SUCCESS ;
@@ -620,7 +620,7 @@ int sbi_dbtr_install_trig(unsigned long smode,return SBI_ERR_NO_SHMEM ; shmem_base =hart_shmem_base (hs); -sbi_hart_protection_map_range ((unsigned long )shmem_base, +sbi_hart_protection_temp_map_range ((unsigned long )shmem_base, trig_count *sizeof (*entry));/*
@@ -639,14 +639,14 @@ int sbi_dbtr_install_trig(unsigned long smode,if (!dbtr_trigger_supported (TDATA1_GET_TYPE (ctrl))) { *out = _idx; -sbi_hart_protection_unmap_range ((unsigned long )shmem_base, +sbi_hart_protection_temp_unmap_range ((unsigned long )shmem_base, trig_count *sizeof (*entry));return SBI_ERR_FAILED ; }if (!dbtr_trigger_valid (TDATA1_GET_TYPE (ctrl), ctrl)) { *out = _idx; -sbi_hart_protection_unmap_range ((unsigned long )shmem_base, +sbi_hart_protection_temp_unmap_range ((unsigned long )shmem_base, trig_count *sizeof (*entry));return SBI_ERR_FAILED ; }
@@ -654,7 +654,7 @@ int sbi_dbtr_install_trig(unsigned long smode,if ((recv->tdata2 && !tdata2_impl) || (recv->tdata3 && !tdata3_impl)) { *out = _idx; -sbi_hart_protection_unmap_range ((unsigned long )shmem_base, +sbi_hart_protection_temp_unmap_range ((unsigned long )shmem_base, trig_count *sizeof (*entry));return SBI_ERR_NOT_SUPPORTED ; }
@@ -662,7 +662,7 @@ int sbi_dbtr_install_trig(unsigned long smode,if (hs->available_trigs < trig_count) { *out = hs->available_trigs; -sbi_hart_protection_unmap_range ((unsigned long )shmem_base, +sbi_hart_protection_temp_unmap_range ((unsigned long )shmem_base, trig_count *sizeof (*entry));return SBI_ERR_FAILED ; }
@@ -684,7 +684,7 @@ int sbi_dbtr_install_trig(unsigned long smode, } -sbi_hart_protection_unmap_range ((unsigned long )shmem_base, +sbi_hart_protection_temp_unmap_range ((unsigned long )shmem_base, trig_count *sizeof (*entry));return SBI_SUCCESS ;
@@ -768,29 +768,29 @@ int sbi_dbtr_update_trig(unsigned long smode, tdata3_impl =tdata_implemented (CSR_TDATA3 );for_each_trig_entry (shmem_base, trig_count,typeof (*entry), entry) { -sbi_hart_protection_map_range ((unsigned long )entry,sizeof (*entry)); +sbi_hart_protection_temp_map_range ((unsigned long )entry,sizeof (*entry)); trig_idx = entry->id.idx;if (trig_idx >= hs->total_trigs) { -sbi_hart_protection_unmap_range ((unsigned long )entry,sizeof (*entry)); +sbi_hart_protection_temp_unmap_range ((unsigned long )entry,sizeof (*entry));return SBI_ERR_INVALID_PARAM ; } trig =INDEX_TO_TRIGGER (trig_idx);if (!(trig->state &RV_DBTR_BIT_MASK (TS ,MAPPED ))) { -sbi_hart_protection_unmap_range ((unsigned long )entry,sizeof (*entry)); +sbi_hart_protection_temp_unmap_range ((unsigned long )entry,sizeof (*entry));return SBI_ERR_FAILED ; }if ((entry->data.tdata2 && !tdata2_impl) || (entry->data.tdata3 && !tdata3_impl)) { -sbi_hart_protection_unmap_range ((unsigned long )entry,sizeof (*entry)); +sbi_hart_protection_temp_unmap_range ((unsigned long )entry,sizeof (*entry));return SBI_ERR_NOT_SUPPORTED ; }dbtr_trigger_setup (trig, &entry->data); -sbi_hart_protection_unmap_range ((unsigned long )entry,sizeof (*entry)); +sbi_hart_protection_temp_unmap_range ((unsigned long )entry,sizeof (*entry));dbtr_trigger_enable (trig); }
lib/sbi/sbi_ecall_dbcn.c +2 -2
@@ -46,12 +46,12 @@ static int sbi_ecall_dbcn_handler(unsigned long extid, unsigned long funcid, regs->a1, regs->a0, smode, SBI_DOMAIN_READ|SBI_DOMAIN_WRITE))return SBI_ERR_INVALID_PARAM ; -sbi_hart_protection_map_range (regs->a1, regs->a0); +sbi_hart_protection_temp_map_range (regs->a1, regs->a0);if (funcid ==SBI_EXT_DBCN_CONSOLE_WRITE ) out->value =sbi_nputs ((const char *)regs->a1, regs->a0);else out->value =sbi_ngets ((char *)regs->a1, regs->a0); -sbi_hart_protection_unmap_range (regs->a1, regs->a0); +sbi_hart_protection_temp_unmap_range (regs->a1, regs->a0);return 0 ;case SBI_EXT_DBCN_CONSOLE_WRITE_BYTE :sbi_putc (regs->a0);
lib/sbi/sbi_hart_pmp.c +5 -5
@@ -135,7 +135,7 @@ int sbi_hart_pmp_get(unsigned int n, unsigned long *prot_out, unsigned long *add* When shared memory access is required, the physical address * should be programmed into the first PMP entry with R/W * permissions to the M-mode. Once the work is done, it should be -* unmapped. sbi_hart_protection_map_range/sbi_hart_protection_unmap_range +* unmapped. sbi_hart_protection_temp_map_range/sbi_hart_protection_temp_unmap_range * function pair should be used to map/unmap the shared memory. */ #define SBI_SMEPMP_RESV_ENTRY 0
@@ -327,7 +327,7 @@ static int sbi_hart_smepmp_configure(struct sbi_scratch *scratch,return 0 ; } -static int sbi_hart_smepmp_map_range (struct sbi_scratch *scratch, +static int sbi_hart_smepmp_temp_map_range (struct sbi_scratch *scratch,unsigned long addr,unsigned long size) {/* shared R/W access for M and S/U mode */
@@ -359,7 +359,7 @@ static int sbi_hart_smepmp_map_range(struct sbi_scratch *scratch,return SBI_OK ; } -static int sbi_hart_smepmp_unmap_range (struct sbi_scratch *scratch, +static int sbi_hart_smepmp_temp_unmap_range (struct sbi_scratch *scratch,unsigned long addr,unsigned long size) {sbi_platform_pmp_disable (sbi_platform_ptr (scratch),SBI_SMEPMP_RESV_ENTRY );
@@ -436,8 +436,8 @@ static struct sbi_hart_protection epmp_protection = { .type = SBI_HART_PROTECTION_TYPE_MEMORY, .configure = sbi_hart_smepmp_configure, .unconfigure = sbi_hart_pmp_unconfigure, - .map_range = sbi_hart_smepmp_map_range, - .unmap_range = sbi_hart_smepmp_unmap_range, + .temp_map_range = sbi_hart_smepmp_temp_map_range, + .temp_unmap_range = sbi_hart_smepmp_temp_unmap_range, };int sbi_hart_pmp_init (struct sbi_scratch *scratch)
lib/sbi/sbi_hart_protection.c +6 -6
@@ -196,22 +196,22 @@ int sbi_hart_protection_reconfigure(struct sbi_scratch *scratch,return 0 ; } -int sbi_hart_protection_map_range (unsigned long base,unsigned long size) +int sbi_hart_protection_temp_map_range (unsigned long base,unsigned long size) {struct sbi_hart_protection *hprot =__hart_memory_protection_best (); -if (!hprot || !hprot->map_range) +if (!hprot || !hprot->temp_map_range)return 0 ; -return hprot->map_range (sbi_scratch_thishart_ptr (), base, size); +return hprot->temp_map_range (sbi_scratch_thishart_ptr (), base, size); } -int sbi_hart_protection_unmap_range (unsigned long base,unsigned long size) +int sbi_hart_protection_temp_unmap_range (unsigned long base,unsigned long size) {struct sbi_hart_protection *hprot =__hart_memory_protection_best (); -if (!hprot || !hprot->unmap_range) +if (!hprot || !hprot->temp_unmap_range)return 0 ; -return hprot->unmap_range (sbi_scratch_thishart_ptr (), base, size); +return hprot->temp_unmap_range (sbi_scratch_thishart_ptr (), base, size); }
lib/sbi/sbi_mpxy.c +12 -12
@@ -401,10 +401,10 @@ int sbi_mpxy_set_shmem(unsigned long shmem_phys_lo,if (flags ==SBI_EXT_MPXY_SHMEM_FLAG_OVERWRITE_RETURN ) { ret_buf = (unsigned long *)(ulong )SHMEM_PHYS_ADDR (shmem_phys_hi, shmem_phys_lo); -sbi_hart_protection_map_range ((unsigned long )ret_buf, mpxy_shmem_size); +sbi_hart_protection_temp_map_range ((unsigned long )ret_buf, mpxy_shmem_size); ret_buf[0 ] =cpu_to_lle (ms->shmem.shmem_addr_lo); ret_buf[1 ] =cpu_to_lle (ms->shmem.shmem_addr_hi); -sbi_hart_protection_unmap_range ((unsigned long )ret_buf, mpxy_shmem_size); +sbi_hart_protection_temp_unmap_range ((unsigned long )ret_buf, mpxy_shmem_size); }/** Setup the new shared memory */
@@ -436,7 +436,7 @@ int sbi_mpxy_get_channel_ids(u32 start_index)return SBI_ERR_INVALID_PARAM ; shmem_base =hart_shmem_base (ms); -sbi_hart_protection_map_range ((unsigned long )hart_shmem_base (ms), mpxy_shmem_size); +sbi_hart_protection_temp_map_range ((unsigned long )hart_shmem_base (ms), mpxy_shmem_size);/** number of channel ids which can be stored in shmem adjusting * for remaining and returned fields */
@@ -466,7 +466,7 @@ int sbi_mpxy_get_channel_ids(u32 start_index) shmem_base[0 ] =cpu_to_le32 (remaining); shmem_base[1 ] =cpu_to_le32 (returned); -sbi_hart_protection_unmap_range ((unsigned long )hart_shmem_base (ms), mpxy_shmem_size); +sbi_hart_protection_temp_unmap_range ((unsigned long )hart_shmem_base (ms), mpxy_shmem_size);return SBI_SUCCESS ; }
@@ -498,7 +498,7 @@ int sbi_mpxy_read_attrs(u32 channel_id, u32 base_attr_id, u32 attr_count) shmem_base =hart_shmem_base (ms); end_id = base_attr_id + attr_count -1 ; -sbi_hart_protection_map_range ((unsigned long )hart_shmem_base (ms), mpxy_shmem_size); +sbi_hart_protection_temp_map_range ((unsigned long )hart_shmem_base (ms), mpxy_shmem_size);/* Standard attributes range check */ if (mpxy_is_std_attr (base_attr_id)) {
@@ -537,7 +537,7 @@ int sbi_mpxy_read_attrs(u32 channel_id, u32 base_attr_id, u32 attr_count) base_attr_id, attr_count); } out: -sbi_hart_protection_unmap_range ((unsigned long )hart_shmem_base (ms), mpxy_shmem_size); +sbi_hart_protection_temp_unmap_range ((unsigned long )hart_shmem_base (ms), mpxy_shmem_size);return ret; }
@@ -650,7 +650,7 @@ int sbi_mpxy_write_attrs(u32 channel_id, u32 base_attr_id, u32 attr_count) shmem_base =hart_shmem_base (ms); end_id = base_attr_id + attr_count -1 ; -sbi_hart_protection_map_range ((unsigned long )shmem_base, mpxy_shmem_size); +sbi_hart_protection_temp_map_range ((unsigned long )shmem_base, mpxy_shmem_size); mem_ptr = (u32 *)shmem_base;
@@ -707,7 +707,7 @@ int sbi_mpxy_write_attrs(u32 channel_id, u32 base_attr_id, u32 attr_count) base_attr_id, attr_count); } out: -sbi_hart_protection_unmap_range ((unsigned long )shmem_base, mpxy_shmem_size); +sbi_hart_protection_temp_unmap_range ((unsigned long )shmem_base, mpxy_shmem_size);return ret; }
@@ -740,7 +740,7 @@ int sbi_mpxy_send_message(u32 channel_id, u8 msg_id,return SBI_ERR_INVALID_PARAM ; shmem_base =hart_shmem_base (ms); -sbi_hart_protection_map_range ((unsigned long )shmem_base, mpxy_shmem_size); +sbi_hart_protection_temp_map_range ((unsigned long )shmem_base, mpxy_shmem_size);if (resp_data_len) { resp_buf = shmem_base;
@@ -757,7 +757,7 @@ int sbi_mpxy_send_message(u32 channel_id, u8 msg_id, msg_data_len); } -sbi_hart_protection_unmap_range ((unsigned long )shmem_base, mpxy_shmem_size); +sbi_hart_protection_temp_unmap_range ((unsigned long )shmem_base, mpxy_shmem_size);if (ret ==SBI_ERR_TIMEOUT || ret ==SBI_ERR_IO )return ret;
@@ -788,12 +788,12 @@ int sbi_mpxy_get_notification_events(u32 channel_id, unsigned long *events_len)return SBI_ERR_NOT_SUPPORTED ; shmem_base =hart_shmem_base (ms); -sbi_hart_protection_map_range ((unsigned long )shmem_base, mpxy_shmem_size); +sbi_hart_protection_temp_map_range ((unsigned long )shmem_base, mpxy_shmem_size); eventsbuf = shmem_base; ret = channel->get_notification_events (channel, eventsbuf, mpxy_shmem_size, events_len); -sbi_hart_protection_unmap_range ((unsigned long )shmem_base, mpxy_shmem_size); +sbi_hart_protection_temp_unmap_range ((unsigned long )shmem_base, mpxy_shmem_size);if (ret)return ret;
lib/sbi/sbi_pmu.c +2 -2
@@ -1093,7 +1093,7 @@ int sbi_pmu_event_get_info(unsigned long shmem_phys_lo, unsigned long shmem_phys SBI_DOMAIN_READ | SBI_DOMAIN_WRITE))return SBI_ERR_INVALID_ADDRESS ; -sbi_hart_protection_map_range (shmem_phys_lo, shmem_size); +sbi_hart_protection_temp_map_range (shmem_phys_lo, shmem_size); einfo = (struct sbi_pmu_event_info *)(shmem_phys_lo);for (i =0 ; i < num_events; i++) {
@@ -1127,7 +1127,7 @@ int sbi_pmu_event_get_info(unsigned long shmem_phys_lo, unsigned long shmem_phys } } -sbi_hart_protection_unmap_range (shmem_phys_lo, shmem_size); +sbi_hart_protection_temp_unmap_range (shmem_phys_lo, shmem_size);return 0 ; }
lib/sbi/sbi_sse.c +4 -4
@@ -1037,7 +1037,7 @@ int sbi_sse_read_attrs(uint32_t event_id, uint32_t base_attr_id,if (ret)return ret; -sbi_hart_protection_map_range (output_phys_lo,sizeof (unsigned long ) * attr_count); +sbi_hart_protection_temp_map_range (output_phys_lo,sizeof (unsigned long ) * attr_count);/* * Copy all attributes at once since struct sse_event_attrs is matching
@@ -1050,7 +1050,7 @@ int sbi_sse_read_attrs(uint32_t event_id, uint32_t base_attr_id, attrs = (unsigned long *)output_phys_lo;copy_attrs (attrs, &e_attrs[base_attr_id], attr_count); -sbi_hart_protection_unmap_range (output_phys_lo,sizeof (unsigned long ) * attr_count); +sbi_hart_protection_temp_unmap_range (output_phys_lo,sizeof (unsigned long ) * attr_count);sse_event_put (e);
@@ -1065,7 +1065,7 @@ static int sse_write_attrs(struct sbi_sse_event *e, uint32_t base_attr_id,uint32_t id, end_id = base_attr_id + attr_count;unsigned long *attrs = (unsigned long *)input_phys; -sbi_hart_protection_map_range (input_phys,sizeof (unsigned long ) * attr_count); +sbi_hart_protection_temp_map_range (input_phys,sizeof (unsigned long ) * attr_count);for (id = base_attr_id; id < end_id; id++) { val = attrs[attr++];
@@ -1081,7 +1081,7 @@ static int sse_write_attrs(struct sbi_sse_event *e, uint32_t base_attr_id, } out: -sbi_hart_protection_unmap_range (input_phys,sizeof (unsigned long ) * attr_count); +sbi_hart_protection_temp_unmap_range (input_phys,sizeof (unsigned long ) * attr_count);return ret; }
Signature · 7 lines
2.53.0 -- opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
Re: [PATCH 1/2] lib: sbi: Rename map_range/unmap_range functions
Quoted 94 lines · Rahul Pathak
*_map_rangeand*_unmap_rangefunctions are required in M-Mode to get the temporary access to S-Mode and U-Mode regions. Thse functions only operate using theTYPE_MEMORYmemory protection mechanisms. Rename them to reflect the actual usage of these functions and let generic map/unmap_range names to implement generic functionsSigned-off-by Rahul Pathak <[email protected]>Reviewed-by Anup Patel <[email protected]>Reviewed-by Pawandeep Oza <[email protected]>--- include/sbi/sbi_hart_protection.h | 27 ++++++++++++++++----------- lib/sbi/sbi_dbtr.c | 26 +++++++++++++------------- lib/sbi/sbi_ecall_dbcn.c | 4 ++-- lib/sbi/sbi_hart_pmp.c | 10 +++++----- lib/sbi/sbi_hart_protection.c | 12 ++++++------ lib/sbi/sbi_mpxy.c | 24 ++++++++++++------------ lib/sbi/sbi_pmu.c | 4 ++-- lib/sbi/sbi_sse.c | 8 ++++---- 8 files changed, 60 insertions(+), 55 deletions(-)include/sbi/sbi_hart_protection.h +16
-11@@ -40,13 +40,17 @@ struct sbi_hart_protection {/** Unconfigure protection for current HART (Optional) */ void (*unconfigure)(struct sbi_scratch *scratch,struct sbi_domain *dom); -/** Create temporary mapping to access address range on current HART (Optional) */ -int (*map_range)(struct sbi_scratch *scratch, -unsigned long base,unsigned long size); - -/** Destroy temporary mapping on current HART (Optional) */ -int (*unmap_range)(struct sbi_scratch *scratch, -unsigned long base,unsigned long size); +/** +* Give temporary M-mode access to an S/U-mode address range on current +* HART (Optional). Only applicable for the TYPE_MEMORY and the TYPE_ID +* mechanisms are not invoked. +*/ +int (*temp_map_range)(struct sbi_scratch *scratch, +unsigned long base,unsigned long size); + +/** Remove the temporary M-mode access on the current HART (Optional) */ +int (*temp_unmap_range)(struct sbi_scratch *scratch, +unsigned long base,unsigned long size); };/** @@ -111,23 +115,24 @@ int sbi_hart_protection_reconfigure(struct sbi_scratch *scratch, struct sbi_domain *next_dom);/** -* Create temporary mapping to access address range on current HART +* Give temporary M-mode access to an S/U-mode address range on the +* current HART. Only valid for TYPE_MEMORY. * * @param base base address of the temporary mapping * @param size size of the temporary mapping * * @return 0 on success and negative error code on failure */ -int sbi_hart_protection_map_range (unsigned long base,unsigned long size); +int sbi_hart_protection_temp_map_range (unsigned long base,unsigned long size);/** -* Destroy temporary mapping to access address range on current HART +* Remove the temporary M-mode access on the current HART * * @param base base address of the temporary mapping * @param size size of the temporary mapping * * @return 0 on success and negative error code on failure */ -int sbi_hart_protection_unmap_range (unsigned long base,unsigned long size); +int sbi_hart_protection_temp_unmap_range (unsigned long base,unsigned long size);#endif /* __SBI_HART_PROTECTION_H__ */ lib/sbi/sbi_dbtr.c +1
-1@@ -580,7 +580,7 @@ int sbi_dbtr_read_trig(unsigned long smode, shmem_base =hart_shmem_base (hs); -sbi_hart_protection_map_range ((unsigned long )shmem_base, +sbi_hart_protection_temp_map_range ((unsigned long )shmem_base, trig_count *sizeof (*entry));for_each_trig_entry (shmem_base, trig_count,typeof (*entry), entry) { xmit = &entry->data;
lib/sbi/sbi_dbtr.c int sbi_dbtr_read_trig(unsigned long smode, · line 597
Quoted 5 lines
lib/sbi/sbi_dbtr.c +1
-1@@ -594,7 +594,7 @@ int sbi_dbtr_read_trig(unsigned long smode, xmit->tdata2 =cpu_to_lle (trig->tdata2); xmit->tdata3 =cpu_to_lle (trig->tdata3); } - sbi_hart_protection_unmap_range((unsigned long)shmem_base, + sbi_hart_protection_temp_unmap_range((unsigned long)shmem_base,
After this change, the next line might be seemingly misaligned. Please cross check at all change points wherever the subsequent call parameter is on the next line.
Quoted 359 lines
lib/sbi/sbi_dbtr.c +11
-11trig_count * sizeof(*entry));return SBI_SUCCESS ;@@ -620,7 +620,7 @@ int sbi_dbtr_install_trig(unsigned long smode,return SBI_ERR_NO_SHMEM ; shmem_base =hart_shmem_base (hs); -sbi_hart_protection_map_range ((unsigned long )shmem_base, +sbi_hart_protection_temp_map_range ((unsigned long )shmem_base, trig_count *sizeof (*entry));/* @@ -639,14 +639,14 @@ int sbi_dbtr_install_trig(unsigned long smode,if (!dbtr_trigger_supported (TDATA1_GET_TYPE (ctrl))) { *out = _idx; -sbi_hart_protection_unmap_range ((unsigned long )shmem_base, +sbi_hart_protection_temp_unmap_range ((unsigned long )shmem_base, trig_count *sizeof (*entry));return SBI_ERR_FAILED ; }if (!dbtr_trigger_valid (TDATA1_GET_TYPE (ctrl), ctrl)) { *out = _idx; -sbi_hart_protection_unmap_range ((unsigned long )shmem_base, +sbi_hart_protection_temp_unmap_range ((unsigned long )shmem_base, trig_count *sizeof (*entry));return SBI_ERR_FAILED ; }@@ -654,7 +654,7 @@ int sbi_dbtr_install_trig(unsigned long smode,if ((recv->tdata2 && !tdata2_impl) || (recv->tdata3 && !tdata3_impl)) { *out = _idx; -sbi_hart_protection_unmap_range ((unsigned long )shmem_base, +sbi_hart_protection_temp_unmap_range ((unsigned long )shmem_base, trig_count *sizeof (*entry));return SBI_ERR_NOT_SUPPORTED ; }@@ -662,7 +662,7 @@ int sbi_dbtr_install_trig(unsigned long smode,if (hs->available_trigs < trig_count) { *out = hs->available_trigs; -sbi_hart_protection_unmap_range ((unsigned long )shmem_base, +sbi_hart_protection_temp_unmap_range ((unsigned long )shmem_base, trig_count *sizeof (*entry));return SBI_ERR_FAILED ; }@@ -684,7 +684,7 @@ int sbi_dbtr_install_trig(unsigned long smode, } -sbi_hart_protection_unmap_range ((unsigned long )shmem_base, +sbi_hart_protection_temp_unmap_range ((unsigned long )shmem_base, trig_count *sizeof (*entry));return SBI_SUCCESS ;@@ -768,29 +768,29 @@ int sbi_dbtr_update_trig(unsigned long smode, tdata3_impl =tdata_implemented (CSR_TDATA3 );for_each_trig_entry (shmem_base, trig_count,typeof (*entry), entry) { -sbi_hart_protection_map_range ((unsigned long )entry,sizeof (*entry)); +sbi_hart_protection_temp_map_range ((unsigned long )entry,sizeof (*entry)); trig_idx = entry->id.idx;if (trig_idx >= hs->total_trigs) { -sbi_hart_protection_unmap_range ((unsigned long )entry,sizeof (*entry)); +sbi_hart_protection_temp_unmap_range ((unsigned long )entry,sizeof (*entry));return SBI_ERR_INVALID_PARAM ; } trig =INDEX_TO_TRIGGER (trig_idx);if (!(trig->state &RV_DBTR_BIT_MASK (TS ,MAPPED ))) { -sbi_hart_protection_unmap_range ((unsigned long )entry,sizeof (*entry)); +sbi_hart_protection_temp_unmap_range ((unsigned long )entry,sizeof (*entry));return SBI_ERR_FAILED ; }if ((entry->data.tdata2 && !tdata2_impl) || (entry->data.tdata3 && !tdata3_impl)) { -sbi_hart_protection_unmap_range ((unsigned long )entry,sizeof (*entry)); +sbi_hart_protection_temp_unmap_range ((unsigned long )entry,sizeof (*entry));return SBI_ERR_NOT_SUPPORTED ; }dbtr_trigger_setup (trig, &entry->data); -sbi_hart_protection_unmap_range ((unsigned long )entry,sizeof (*entry)); +sbi_hart_protection_temp_unmap_range ((unsigned long )entry,sizeof (*entry));dbtr_trigger_enable (trig); }lib/sbi/sbi_ecall_dbcn.c +2
-2@@ -46,12 +46,12 @@ static int sbi_ecall_dbcn_handler(unsigned long extid, unsigned long funcid, regs->a1, regs->a0, smode, SBI_DOMAIN_READ|SBI_DOMAIN_WRITE))return SBI_ERR_INVALID_PARAM ; -sbi_hart_protection_map_range (regs->a1, regs->a0); +sbi_hart_protection_temp_map_range (regs->a1, regs->a0);if (funcid ==SBI_EXT_DBCN_CONSOLE_WRITE ) out->value =sbi_nputs ((const char *)regs->a1, regs->a0);else out->value =sbi_ngets ((char *)regs->a1, regs->a0); -sbi_hart_protection_unmap_range (regs->a1, regs->a0); +sbi_hart_protection_temp_unmap_range (regs->a1, regs->a0);return 0 ;case SBI_EXT_DBCN_CONSOLE_WRITE_BYTE :sbi_putc (regs->a0);lib/sbi/sbi_hart_pmp.c +5
-5@@ -135,7 +135,7 @@ int sbi_hart_pmp_get(unsigned int n, unsigned long *prot_out, unsigned long *add* When shared memory access is required, the physical address * should be programmed into the first PMP entry with R/W * permissions to the M-mode. Once the work is done, it should be -* unmapped. sbi_hart_protection_map_range/sbi_hart_protection_unmap_range +* unmapped. sbi_hart_protection_temp_map_range/sbi_hart_protection_temp_unmap_range * function pair should be used to map/unmap the shared memory. */ #define SBI_SMEPMP_RESV_ENTRY 0@@ -327,7 +327,7 @@ static int sbi_hart_smepmp_configure(struct sbi_scratch *scratch,return 0 ; } -static int sbi_hart_smepmp_map_range (struct sbi_scratch *scratch, +static int sbi_hart_smepmp_temp_map_range (struct sbi_scratch *scratch,unsigned long addr,unsigned long size) {/* shared R/W access for M and S/U mode */ @@ -359,7 +359,7 @@ static int sbi_hart_smepmp_map_range(struct sbi_scratch *scratch,return SBI_OK ; } -static int sbi_hart_smepmp_unmap_range (struct sbi_scratch *scratch, +static int sbi_hart_smepmp_temp_unmap_range (struct sbi_scratch *scratch,unsigned long addr,unsigned long size) {sbi_platform_pmp_disable (sbi_platform_ptr (scratch),SBI_SMEPMP_RESV_ENTRY );@@ -436,8 +436,8 @@ static struct sbi_hart_protection epmp_protection = { .type = SBI_HART_PROTECTION_TYPE_MEMORY, .configure = sbi_hart_smepmp_configure, .unconfigure = sbi_hart_pmp_unconfigure, - .map_range = sbi_hart_smepmp_map_range, - .unmap_range = sbi_hart_smepmp_unmap_range, + .temp_map_range = sbi_hart_smepmp_temp_map_range, + .temp_unmap_range = sbi_hart_smepmp_temp_unmap_range, };int sbi_hart_pmp_init (struct sbi_scratch *scratch)lib/sbi/sbi_hart_protection.c +6
-6@@ -196,22 +196,22 @@ int sbi_hart_protection_reconfigure(struct sbi_scratch *scratch,return 0 ; } -int sbi_hart_protection_map_range (unsigned long base,unsigned long size) +int sbi_hart_protection_temp_map_range (unsigned long base,unsigned long size) {struct sbi_hart_protection *hprot =__hart_memory_protection_best (); -if (!hprot || !hprot->map_range) +if (!hprot || !hprot->temp_map_range)return 0 ; -return hprot->map_range (sbi_scratch_thishart_ptr (), base, size); +return hprot->temp_map_range (sbi_scratch_thishart_ptr (), base, size); } -int sbi_hart_protection_unmap_range (unsigned long base,unsigned long size) +int sbi_hart_protection_temp_unmap_range (unsigned long base,unsigned long size) {struct sbi_hart_protection *hprot =__hart_memory_protection_best (); -if (!hprot || !hprot->unmap_range) +if (!hprot || !hprot->temp_unmap_range)return 0 ; -return hprot->unmap_range (sbi_scratch_thishart_ptr (), base, size); +return hprot->temp_unmap_range (sbi_scratch_thishart_ptr (), base, size); }lib/sbi/sbi_mpxy.c +12
-12@@ -401,10 +401,10 @@ int sbi_mpxy_set_shmem(unsigned long shmem_phys_lo,if (flags ==SBI_EXT_MPXY_SHMEM_FLAG_OVERWRITE_RETURN ) { ret_buf = (unsigned long *)(ulong )SHMEM_PHYS_ADDR (shmem_phys_hi, shmem_phys_lo); -sbi_hart_protection_map_range ((unsigned long )ret_buf, mpxy_shmem_size); +sbi_hart_protection_temp_map_range ((unsigned long )ret_buf, mpxy_shmem_size); ret_buf[0 ] =cpu_to_lle (ms->shmem.shmem_addr_lo); ret_buf[1 ] =cpu_to_lle (ms->shmem.shmem_addr_hi); -sbi_hart_protection_unmap_range ((unsigned long )ret_buf, mpxy_shmem_size); +sbi_hart_protection_temp_unmap_range ((unsigned long )ret_buf, mpxy_shmem_size); }/** Setup the new shared memory */ @@ -436,7 +436,7 @@ int sbi_mpxy_get_channel_ids(u32 start_index)return SBI_ERR_INVALID_PARAM ; shmem_base =hart_shmem_base (ms); -sbi_hart_protection_map_range ((unsigned long )hart_shmem_base (ms), mpxy_shmem_size); +sbi_hart_protection_temp_map_range ((unsigned long )hart_shmem_base (ms), mpxy_shmem_size);/** number of channel ids which can be stored in shmem adjusting * for remaining and returned fields */ @@ -466,7 +466,7 @@ int sbi_mpxy_get_channel_ids(u32 start_index) shmem_base[0 ] =cpu_to_le32 (remaining); shmem_base[1 ] =cpu_to_le32 (returned); -sbi_hart_protection_unmap_range ((unsigned long )hart_shmem_base (ms), mpxy_shmem_size); +sbi_hart_protection_temp_unmap_range ((unsigned long )hart_shmem_base (ms), mpxy_shmem_size);return SBI_SUCCESS ; }@@ -498,7 +498,7 @@ int sbi_mpxy_read_attrs(u32 channel_id, u32 base_attr_id, u32 attr_count) shmem_base =hart_shmem_base (ms); end_id = base_attr_id + attr_count -1 ; -sbi_hart_protection_map_range ((unsigned long )hart_shmem_base (ms), mpxy_shmem_size); +sbi_hart_protection_temp_map_range ((unsigned long )hart_shmem_base (ms), mpxy_shmem_size);/* Standard attributes range check */ if (mpxy_is_std_attr (base_attr_id)) {@@ -537,7 +537,7 @@ int sbi_mpxy_read_attrs(u32 channel_id, u32 base_attr_id, u32 attr_count) base_attr_id, attr_count); } out: -sbi_hart_protection_unmap_range ((unsigned long )hart_shmem_base (ms), mpxy_shmem_size); +sbi_hart_protection_temp_unmap_range ((unsigned long )hart_shmem_base (ms), mpxy_shmem_size);return ret; }@@ -650,7 +650,7 @@ int sbi_mpxy_write_attrs(u32 channel_id, u32 base_attr_id, u32 attr_count) shmem_base =hart_shmem_base (ms); end_id = base_attr_id + attr_count -1 ; -sbi_hart_protection_map_range ((unsigned long )shmem_base, mpxy_shmem_size); +sbi_hart_protection_temp_map_range ((unsigned long )shmem_base, mpxy_shmem_size); mem_ptr = (u32 *)shmem_base;@@ -707,7 +707,7 @@ int sbi_mpxy_write_attrs(u32 channel_id, u32 base_attr_id, u32 attr_count) base_attr_id, attr_count); } out: -sbi_hart_protection_unmap_range ((unsigned long )shmem_base, mpxy_shmem_size); +sbi_hart_protection_temp_unmap_range ((unsigned long )shmem_base, mpxy_shmem_size);return ret; }@@ -740,7 +740,7 @@ int sbi_mpxy_send_message(u32 channel_id, u8 msg_id,return SBI_ERR_INVALID_PARAM ; shmem_base =hart_shmem_base (ms); -sbi_hart_protection_map_range ((unsigned long )shmem_base, mpxy_shmem_size); +sbi_hart_protection_temp_map_range ((unsigned long )shmem_base, mpxy_shmem_size);if (resp_data_len) { resp_buf = shmem_base;@@ -757,7 +757,7 @@ int sbi_mpxy_send_message(u32 channel_id, u8 msg_id, msg_data_len); } -sbi_hart_protection_unmap_range ((unsigned long )shmem_base, mpxy_shmem_size); +sbi_hart_protection_temp_unmap_range ((unsigned long )shmem_base, mpxy_shmem_size);if (ret ==SBI_ERR_TIMEOUT || ret ==SBI_ERR_IO )return ret;@@ -788,12 +788,12 @@ int sbi_mpxy_get_notification_events(u32 channel_id, unsigned long *events_len)return SBI_ERR_NOT_SUPPORTED ; shmem_base =hart_shmem_base (ms); -sbi_hart_protection_map_range ((unsigned long )shmem_base, mpxy_shmem_size); +sbi_hart_protection_temp_map_range ((unsigned long )shmem_base, mpxy_shmem_size); eventsbuf = shmem_base; ret = channel->get_notification_events (channel, eventsbuf, mpxy_shmem_size, events_len); -sbi_hart_protection_unmap_range ((unsigned long )shmem_base, mpxy_shmem_size); +sbi_hart_protection_temp_unmap_range ((unsigned long )shmem_base, mpxy_shmem_size);if (ret)return ret;lib/sbi/sbi_pmu.c +2
-2@@ -1093,7 +1093,7 @@ int sbi_pmu_event_get_info(unsigned long shmem_phys_lo, unsigned long shmem_phys SBI_DOMAIN_READ | SBI_DOMAIN_WRITE))return SBI_ERR_INVALID_ADDRESS ; -sbi_hart_protection_map_range (shmem_phys_lo, shmem_size); +sbi_hart_protection_temp_map_range (shmem_phys_lo, shmem_size); einfo = (struct sbi_pmu_event_info *)(shmem_phys_lo);for (i =0 ; i < num_events; i++) {@@ -1127,7 +1127,7 @@ int sbi_pmu_event_get_info(unsigned long shmem_phys_lo, unsigned long shmem_phys } } -sbi_hart_protection_unmap_range (shmem_phys_lo, shmem_size); +sbi_hart_protection_temp_unmap_range (shmem_phys_lo, shmem_size);return 0 ; }lib/sbi/sbi_sse.c +4
-5@@ -1037,7 +1037,7 @@ int sbi_sse_read_attrs(uint32_t event_id, uint32_t base_attr_id,if (ret)return ret; -sbi_hart_protection_map_range (output_phys_lo,sizeof (unsigned long ) * attr_count); +sbi_hart_protection_temp_map_range (output_phys_lo,sizeof (unsigned long ) * attr_count);/* * Copy all attributes at once since struct sse_event_attrs is matching @@ -1050,7 +1050,7 @@ int sbi_sse_read_attrs(uint32_t event_id, uint32_t base_attr_id, attrs = (unsigned long *)output_phys_lo;copy_attrs (attrs, &e_attrs[base_attr_id], attr_count); -sbi_hart_protection_unmap_range (output_phys_lo,sizeof (unsigned long ) * attr_count); +sbi_hart_protection_temp_unmap_range (output_phys_lo,sizeof (unsigned long ) * attr_count);sse_event_put (e);@@ -1065,7 +1065,7 @@ static int sse_write_attrs(struct sbi_sse_event *e, uint32_t base_attr_id,uint32_t id, end_id = base_attr_id + attr_count;unsigned long *attrs = (unsigned long *)input_phys; -sbi_hart_protection_map_range (input_phys,sizeof (unsigned long ) * attr_count); +sbi_hart_protection_temp_map_range (input_phys,sizeof (unsigned long ) * attr_count);for (id = base_attr_id; id < end_id; id++) { val = attrs[attr++];@@ -1081,7 +1081,7 @@ static int sse_write_attrs(struct sbi_sse_event *e, uint32_t base_attr_id, } out: -sbi_hart_protection_unmap_range (input_phys,sizeof (unsigned long ) * attr_count); +sbi_hart_protection_temp_unmap_range (input_phys,sizeof (unsigned long ) * attr_count);return ret; } --2.53.0
--
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
Signature · 3 lines
opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
Anup Patel
AppliedRe: [PATCH 1/2] lib: sbi: Rename map_range/unmap_range functions
In reply to Rahul PathakQuoted 11 lines · Rahul Pathak
*_map_rangeand*_unmap_rangefunctions are required in M-Mode to get the temporary access to S-Mode and U-Mode regions. Thse functions only operate using theTYPE_MEMORYmemory protection mechanisms. Rename them to reflect the actual usage of these functions and let generic map/unmap_range names to implement generic functionsSigned-off-by Rahul Pathak <[email protected]>Reviewed-by Anup Patel <[email protected]>Reviewed-by Pawandeep Oza <[email protected]>
I have addressed code alignment issues pointed by Ranbir at the time of merging.
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
Quoted 447 lines
--- include/sbi/sbi_hart_protection.h | 27 ++++++++++++++++----------- lib/sbi/sbi_dbtr.c | 26 +++++++++++++------------- lib/sbi/sbi_ecall_dbcn.c | 4 ++-- lib/sbi/sbi_hart_pmp.c | 10 +++++----- lib/sbi/sbi_hart_protection.c | 12 ++++++------ lib/sbi/sbi_mpxy.c | 24 ++++++++++++------------ lib/sbi/sbi_pmu.c | 4 ++-- lib/sbi/sbi_sse.c | 8 ++++---- 8 files changed, 60 insertions(+), 55 deletions(-)include/sbi/sbi_hart_protection.h +16
-11@@ -40,13 +40,17 @@ struct sbi_hart_protection {/** Unconfigure protection for current HART (Optional) */ void (*unconfigure)(struct sbi_scratch *scratch,struct sbi_domain *dom); -/** Create temporary mapping to access address range on current HART (Optional) */ -int (*map_range)(struct sbi_scratch *scratch, -unsigned long base,unsigned long size); - -/** Destroy temporary mapping on current HART (Optional) */ -int (*unmap_range)(struct sbi_scratch *scratch, -unsigned long base,unsigned long size); +/** +* Give temporary M-mode access to an S/U-mode address range on current +* HART (Optional). Only applicable for the TYPE_MEMORY and the TYPE_ID +* mechanisms are not invoked. +*/ +int (*temp_map_range)(struct sbi_scratch *scratch, +unsigned long base,unsigned long size); + +/** Remove the temporary M-mode access on the current HART (Optional) */ +int (*temp_unmap_range)(struct sbi_scratch *scratch, +unsigned long base,unsigned long size); };/** @@ -111,23 +115,24 @@ int sbi_hart_protection_reconfigure(struct sbi_scratch *scratch, struct sbi_domain *next_dom);/** -* Create temporary mapping to access address range on current HART +* Give temporary M-mode access to an S/U-mode address range on the +* current HART. Only valid for TYPE_MEMORY. * * @param base base address of the temporary mapping * @param size size of the temporary mapping * * @return 0 on success and negative error code on failure */ -int sbi_hart_protection_map_range (unsigned long base,unsigned long size); +int sbi_hart_protection_temp_map_range (unsigned long base,unsigned long size);/** -* Destroy temporary mapping to access address range on current HART +* Remove the temporary M-mode access on the current HART * * @param base base address of the temporary mapping * @param size size of the temporary mapping * * @return 0 on success and negative error code on failure */ -int sbi_hart_protection_unmap_range (unsigned long base,unsigned long size); +int sbi_hart_protection_temp_unmap_range (unsigned long base,unsigned long size);#endif /* __SBI_HART_PROTECTION_H__ */ lib/sbi/sbi_dbtr.c +13
-13@@ -580,7 +580,7 @@ int sbi_dbtr_read_trig(unsigned long smode, shmem_base =hart_shmem_base (hs); -sbi_hart_protection_map_range ((unsigned long )shmem_base, +sbi_hart_protection_temp_map_range ((unsigned long )shmem_base, trig_count *sizeof (*entry));for_each_trig_entry (shmem_base, trig_count,typeof (*entry), entry) { xmit = &entry->data;@@ -594,7 +594,7 @@ int sbi_dbtr_read_trig(unsigned long smode, xmit->tdata2 =cpu_to_lle (trig->tdata2); xmit->tdata3 =cpu_to_lle (trig->tdata3); } -sbi_hart_protection_unmap_range ((unsigned long )shmem_base, +sbi_hart_protection_temp_unmap_range ((unsigned long )shmem_base, trig_count *sizeof (*entry));return SBI_SUCCESS ;@@ -620,7 +620,7 @@ int sbi_dbtr_install_trig(unsigned long smode,return SBI_ERR_NO_SHMEM ; shmem_base =hart_shmem_base (hs); -sbi_hart_protection_map_range ((unsigned long )shmem_base, +sbi_hart_protection_temp_map_range ((unsigned long )shmem_base, trig_count *sizeof (*entry));/* @@ -639,14 +639,14 @@ int sbi_dbtr_install_trig(unsigned long smode,if (!dbtr_trigger_supported (TDATA1_GET_TYPE (ctrl))) { *out = _idx; -sbi_hart_protection_unmap_range ((unsigned long )shmem_base, +sbi_hart_protection_temp_unmap_range ((unsigned long )shmem_base, trig_count *sizeof (*entry));return SBI_ERR_FAILED ; }if (!dbtr_trigger_valid (TDATA1_GET_TYPE (ctrl), ctrl)) { *out = _idx; -sbi_hart_protection_unmap_range ((unsigned long )shmem_base, +sbi_hart_protection_temp_unmap_range ((unsigned long )shmem_base, trig_count *sizeof (*entry));return SBI_ERR_FAILED ; }@@ -654,7 +654,7 @@ int sbi_dbtr_install_trig(unsigned long smode,if ((recv->tdata2 && !tdata2_impl) || (recv->tdata3 && !tdata3_impl)) { *out = _idx; -sbi_hart_protection_unmap_range ((unsigned long )shmem_base, +sbi_hart_protection_temp_unmap_range ((unsigned long )shmem_base, trig_count *sizeof (*entry));return SBI_ERR_NOT_SUPPORTED ; }@@ -662,7 +662,7 @@ int sbi_dbtr_install_trig(unsigned long smode,if (hs->available_trigs < trig_count) { *out = hs->available_trigs; -sbi_hart_protection_unmap_range ((unsigned long )shmem_base, +sbi_hart_protection_temp_unmap_range ((unsigned long )shmem_base, trig_count *sizeof (*entry));return SBI_ERR_FAILED ; }@@ -684,7 +684,7 @@ int sbi_dbtr_install_trig(unsigned long smode, } -sbi_hart_protection_unmap_range ((unsigned long )shmem_base, +sbi_hart_protection_temp_unmap_range ((unsigned long )shmem_base, trig_count *sizeof (*entry));return SBI_SUCCESS ;@@ -768,29 +768,29 @@ int sbi_dbtr_update_trig(unsigned long smode, tdata3_impl =tdata_implemented (CSR_TDATA3 );for_each_trig_entry (shmem_base, trig_count,typeof (*entry), entry) { -sbi_hart_protection_map_range ((unsigned long )entry,sizeof (*entry)); +sbi_hart_protection_temp_map_range ((unsigned long )entry,sizeof (*entry)); trig_idx = entry->id.idx;if (trig_idx >= hs->total_trigs) { -sbi_hart_protection_unmap_range ((unsigned long )entry,sizeof (*entry)); +sbi_hart_protection_temp_unmap_range ((unsigned long )entry,sizeof (*entry));return SBI_ERR_INVALID_PARAM ; } trig =INDEX_TO_TRIGGER (trig_idx);if (!(trig->state &RV_DBTR_BIT_MASK (TS ,MAPPED ))) { -sbi_hart_protection_unmap_range ((unsigned long )entry,sizeof (*entry)); +sbi_hart_protection_temp_unmap_range ((unsigned long )entry,sizeof (*entry));return SBI_ERR_FAILED ; }if ((entry->data.tdata2 && !tdata2_impl) || (entry->data.tdata3 && !tdata3_impl)) { -sbi_hart_protection_unmap_range ((unsigned long )entry,sizeof (*entry)); +sbi_hart_protection_temp_unmap_range ((unsigned long )entry,sizeof (*entry));return SBI_ERR_NOT_SUPPORTED ; }dbtr_trigger_setup (trig, &entry->data); -sbi_hart_protection_unmap_range ((unsigned long )entry,sizeof (*entry)); +sbi_hart_protection_temp_unmap_range ((unsigned long )entry,sizeof (*entry));dbtr_trigger_enable (trig); }lib/sbi/sbi_ecall_dbcn.c +2
-2@@ -46,12 +46,12 @@ static int sbi_ecall_dbcn_handler(unsigned long extid, unsigned long funcid, regs->a1, regs->a0, smode, SBI_DOMAIN_READ|SBI_DOMAIN_WRITE))return SBI_ERR_INVALID_PARAM ; -sbi_hart_protection_map_range (regs->a1, regs->a0); +sbi_hart_protection_temp_map_range (regs->a1, regs->a0);if (funcid ==SBI_EXT_DBCN_CONSOLE_WRITE ) out->value =sbi_nputs ((const char *)regs->a1, regs->a0);else out->value =sbi_ngets ((char *)regs->a1, regs->a0); -sbi_hart_protection_unmap_range (regs->a1, regs->a0); +sbi_hart_protection_temp_unmap_range (regs->a1, regs->a0);return 0 ;case SBI_EXT_DBCN_CONSOLE_WRITE_BYTE :sbi_putc (regs->a0);lib/sbi/sbi_hart_pmp.c +5
-5@@ -135,7 +135,7 @@ int sbi_hart_pmp_get(unsigned int n, unsigned long *prot_out, unsigned long *add* When shared memory access is required, the physical address * should be programmed into the first PMP entry with R/W * permissions to the M-mode. Once the work is done, it should be -* unmapped. sbi_hart_protection_map_range/sbi_hart_protection_unmap_range +* unmapped. sbi_hart_protection_temp_map_range/sbi_hart_protection_temp_unmap_range * function pair should be used to map/unmap the shared memory. */ #define SBI_SMEPMP_RESV_ENTRY 0@@ -327,7 +327,7 @@ static int sbi_hart_smepmp_configure(struct sbi_scratch *scratch,return 0 ; } -static int sbi_hart_smepmp_map_range (struct sbi_scratch *scratch, +static int sbi_hart_smepmp_temp_map_range (struct sbi_scratch *scratch,unsigned long addr,unsigned long size) {/* shared R/W access for M and S/U mode */ @@ -359,7 +359,7 @@ static int sbi_hart_smepmp_map_range(struct sbi_scratch *scratch,return SBI_OK ; } -static int sbi_hart_smepmp_unmap_range (struct sbi_scratch *scratch, +static int sbi_hart_smepmp_temp_unmap_range (struct sbi_scratch *scratch,unsigned long addr,unsigned long size) {sbi_platform_pmp_disable (sbi_platform_ptr (scratch),SBI_SMEPMP_RESV_ENTRY );@@ -436,8 +436,8 @@ static struct sbi_hart_protection epmp_protection = { .type = SBI_HART_PROTECTION_TYPE_MEMORY, .configure = sbi_hart_smepmp_configure, .unconfigure = sbi_hart_pmp_unconfigure, - .map_range = sbi_hart_smepmp_map_range, - .unmap_range = sbi_hart_smepmp_unmap_range, + .temp_map_range = sbi_hart_smepmp_temp_map_range, + .temp_unmap_range = sbi_hart_smepmp_temp_unmap_range, };int sbi_hart_pmp_init (struct sbi_scratch *scratch)lib/sbi/sbi_hart_protection.c +6
-6@@ -196,22 +196,22 @@ int sbi_hart_protection_reconfigure(struct sbi_scratch *scratch,return 0 ; } -int sbi_hart_protection_map_range (unsigned long base,unsigned long size) +int sbi_hart_protection_temp_map_range (unsigned long base,unsigned long size) {struct sbi_hart_protection *hprot =__hart_memory_protection_best (); -if (!hprot || !hprot->map_range) +if (!hprot || !hprot->temp_map_range)return 0 ; -return hprot->map_range (sbi_scratch_thishart_ptr (), base, size); +return hprot->temp_map_range (sbi_scratch_thishart_ptr (), base, size); } -int sbi_hart_protection_unmap_range (unsigned long base,unsigned long size) +int sbi_hart_protection_temp_unmap_range (unsigned long base,unsigned long size) {struct sbi_hart_protection *hprot =__hart_memory_protection_best (); -if (!hprot || !hprot->unmap_range) +if (!hprot || !hprot->temp_unmap_range)return 0 ; -return hprot->unmap_range (sbi_scratch_thishart_ptr (), base, size); +return hprot->temp_unmap_range (sbi_scratch_thishart_ptr (), base, size); }lib/sbi/sbi_mpxy.c +12
-12@@ -401,10 +401,10 @@ int sbi_mpxy_set_shmem(unsigned long shmem_phys_lo,if (flags ==SBI_EXT_MPXY_SHMEM_FLAG_OVERWRITE_RETURN ) { ret_buf = (unsigned long *)(ulong )SHMEM_PHYS_ADDR (shmem_phys_hi, shmem_phys_lo); -sbi_hart_protection_map_range ((unsigned long )ret_buf, mpxy_shmem_size); +sbi_hart_protection_temp_map_range ((unsigned long )ret_buf, mpxy_shmem_size); ret_buf[0 ] =cpu_to_lle (ms->shmem.shmem_addr_lo); ret_buf[1 ] =cpu_to_lle (ms->shmem.shmem_addr_hi); -sbi_hart_protection_unmap_range ((unsigned long )ret_buf, mpxy_shmem_size); +sbi_hart_protection_temp_unmap_range ((unsigned long )ret_buf, mpxy_shmem_size); }/** Setup the new shared memory */ @@ -436,7 +436,7 @@ int sbi_mpxy_get_channel_ids(u32 start_index)return SBI_ERR_INVALID_PARAM ; shmem_base =hart_shmem_base (ms); -sbi_hart_protection_map_range ((unsigned long )hart_shmem_base (ms), mpxy_shmem_size); +sbi_hart_protection_temp_map_range ((unsigned long )hart_shmem_base (ms), mpxy_shmem_size);/** number of channel ids which can be stored in shmem adjusting * for remaining and returned fields */ @@ -466,7 +466,7 @@ int sbi_mpxy_get_channel_ids(u32 start_index) shmem_base[0 ] =cpu_to_le32 (remaining); shmem_base[1 ] =cpu_to_le32 (returned); -sbi_hart_protection_unmap_range ((unsigned long )hart_shmem_base (ms), mpxy_shmem_size); +sbi_hart_protection_temp_unmap_range ((unsigned long )hart_shmem_base (ms), mpxy_shmem_size);return SBI_SUCCESS ; }@@ -498,7 +498,7 @@ int sbi_mpxy_read_attrs(u32 channel_id, u32 base_attr_id, u32 attr_count) shmem_base =hart_shmem_base (ms); end_id = base_attr_id + attr_count -1 ; -sbi_hart_protection_map_range ((unsigned long )hart_shmem_base (ms), mpxy_shmem_size); +sbi_hart_protection_temp_map_range ((unsigned long )hart_shmem_base (ms), mpxy_shmem_size);/* Standard attributes range check */ if (mpxy_is_std_attr (base_attr_id)) {@@ -537,7 +537,7 @@ int sbi_mpxy_read_attrs(u32 channel_id, u32 base_attr_id, u32 attr_count) base_attr_id, attr_count); } out: -sbi_hart_protection_unmap_range ((unsigned long )hart_shmem_base (ms), mpxy_shmem_size); +sbi_hart_protection_temp_unmap_range ((unsigned long )hart_shmem_base (ms), mpxy_shmem_size);return ret; }@@ -650,7 +650,7 @@ int sbi_mpxy_write_attrs(u32 channel_id, u32 base_attr_id, u32 attr_count) shmem_base =hart_shmem_base (ms); end_id = base_attr_id + attr_count -1 ; -sbi_hart_protection_map_range ((unsigned long )shmem_base, mpxy_shmem_size); +sbi_hart_protection_temp_map_range ((unsigned long )shmem_base, mpxy_shmem_size); mem_ptr = (u32 *)shmem_base;@@ -707,7 +707,7 @@ int sbi_mpxy_write_attrs(u32 channel_id, u32 base_attr_id, u32 attr_count) base_attr_id, attr_count); } out: -sbi_hart_protection_unmap_range ((unsigned long )shmem_base, mpxy_shmem_size); +sbi_hart_protection_temp_unmap_range ((unsigned long )shmem_base, mpxy_shmem_size);return ret; }@@ -740,7 +740,7 @@ int sbi_mpxy_send_message(u32 channel_id, u8 msg_id,return SBI_ERR_INVALID_PARAM ; shmem_base =hart_shmem_base (ms); -sbi_hart_protection_map_range ((unsigned long )shmem_base, mpxy_shmem_size); +sbi_hart_protection_temp_map_range ((unsigned long )shmem_base, mpxy_shmem_size);if (resp_data_len) { resp_buf = shmem_base;@@ -757,7 +757,7 @@ int sbi_mpxy_send_message(u32 channel_id, u8 msg_id, msg_data_len); } -sbi_hart_protection_unmap_range ((unsigned long )shmem_base, mpxy_shmem_size); +sbi_hart_protection_temp_unmap_range ((unsigned long )shmem_base, mpxy_shmem_size);if (ret ==SBI_ERR_TIMEOUT || ret ==SBI_ERR_IO )return ret;@@ -788,12 +788,12 @@ int sbi_mpxy_get_notification_events(u32 channel_id, unsigned long *events_len)return SBI_ERR_NOT_SUPPORTED ; shmem_base =hart_shmem_base (ms); -sbi_hart_protection_map_range ((unsigned long )shmem_base, mpxy_shmem_size); +sbi_hart_protection_temp_map_range ((unsigned long )shmem_base, mpxy_shmem_size); eventsbuf = shmem_base; ret = channel->get_notification_events (channel, eventsbuf, mpxy_shmem_size, events_len); -sbi_hart_protection_unmap_range ((unsigned long )shmem_base, mpxy_shmem_size); +sbi_hart_protection_temp_unmap_range ((unsigned long )shmem_base, mpxy_shmem_size);if (ret)return ret;lib/sbi/sbi_pmu.c +2
-2@@ -1093,7 +1093,7 @@ int sbi_pmu_event_get_info(unsigned long shmem_phys_lo, unsigned long shmem_phys SBI_DOMAIN_READ | SBI_DOMAIN_WRITE))return SBI_ERR_INVALID_ADDRESS ; -sbi_hart_protection_map_range (shmem_phys_lo, shmem_size); +sbi_hart_protection_temp_map_range (shmem_phys_lo, shmem_size); einfo = (struct sbi_pmu_event_info *)(shmem_phys_lo);for (i =0 ; i < num_events; i++) {@@ -1127,7 +1127,7 @@ int sbi_pmu_event_get_info(unsigned long shmem_phys_lo, unsigned long shmem_phys } } -sbi_hart_protection_unmap_range (shmem_phys_lo, shmem_size); +sbi_hart_protection_temp_unmap_range (shmem_phys_lo, shmem_size);return 0 ; }lib/sbi/sbi_sse.c +4
-5@@ -1037,7 +1037,7 @@ int sbi_sse_read_attrs(uint32_t event_id, uint32_t base_attr_id,if (ret)return ret; -sbi_hart_protection_map_range (output_phys_lo,sizeof (unsigned long ) * attr_count); +sbi_hart_protection_temp_map_range (output_phys_lo,sizeof (unsigned long ) * attr_count);/* * Copy all attributes at once since struct sse_event_attrs is matching @@ -1050,7 +1050,7 @@ int sbi_sse_read_attrs(uint32_t event_id, uint32_t base_attr_id, attrs = (unsigned long *)output_phys_lo;copy_attrs (attrs, &e_attrs[base_attr_id], attr_count); -sbi_hart_protection_unmap_range (output_phys_lo,sizeof (unsigned long ) * attr_count); +sbi_hart_protection_temp_unmap_range (output_phys_lo,sizeof (unsigned long ) * attr_count);sse_event_put (e);@@ -1065,7 +1065,7 @@ static int sse_write_attrs(struct sbi_sse_event *e, uint32_t base_attr_id,uint32_t id, end_id = base_attr_id + attr_count;unsigned long *attrs = (unsigned long *)input_phys; -sbi_hart_protection_map_range (input_phys,sizeof (unsigned long ) * attr_count); +sbi_hart_protection_temp_map_range (input_phys,sizeof (unsigned long ) * attr_count);for (id = base_attr_id; id < end_id; id++) { val = attrs[attr++];@@ -1081,7 +1081,7 @@ static int sse_write_attrs(struct sbi_sse_event *e, uint32_t base_attr_id, } out: -sbi_hart_protection_unmap_range (input_phys,sizeof (unsigned long ) * attr_count); +sbi_hart_protection_temp_unmap_range (input_phys,sizeof (unsigned long ) * attr_count);return ret; } --2.53.0
--
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
Signature · 3 lines
opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
PATCH 2/2 lib: sbi_domain: Rename per-domain data to per-domain state
In reply to Rahul PathakThe per-domain sbi_domain_data hold each domain associated state like hart context in sbi_domain_context, mpxy state in sbi_mpxy, and others like each domain backed by the corresponding MPT (SMMPT).
DATA reads as a generic name, while every use stores state. Rename functions and macros appropriately. There are no functional changes.
--- include/sbi/sbi_domain.h | 6 +- include/sbi/sbi_domain_data.h | 93 ---------------------- include/sbi/sbi_domain_state.h | 93 ++++++++++++++++++++++ lib/sbi/objects.mk | 2 +- lib/sbi/sbi_domain.c | 6 +- lib/sbi/sbi_domain_context.c | 14 ++-- lib/sbi/sbi_domain_data.c | 138 --------------------------------- lib/sbi/sbi_domain_state.c | 138 +++++++++++++++++++++++++++++++++ lib/sbi/sbi_mpxy.c | 32 ++++---- 9 files changed, 261 insertions(+), 261 deletions(-) delete mode 100644 include/sbi/sbi_domain_data.h create mode 100644 include/sbi/sbi_domain_state.h delete mode 100644 lib/sbi/sbi_domain_data.c create mode 100644 lib/sbi/sbi_domain_state.c
include/sbi/sbi_domain.h +3 -3
@@ -15,7 +15,7 @@#include <sbi/sbi_types.h> #include <sbi/sbi_hartmask.h> #include <sbi/sbi_domain_context.h> -#include <sbi/sbi_domain_data.h> +#include <sbi/sbi_domain_state.h> struct sbi_scratch ;
@@ -189,8 +189,8 @@ static inline bool sbi_domain_memregion_is_subset(struct sbi_domain {/** Node in linked list of domains */ struct sbi_dlist node; -/** Internal state of per-domain data */ -struct sbi_domain_data_priv data_priv; +/** Internal per-domain state areas */ +struct sbi_domain_state_priv state_priv;/** Logical index of this domain */ u32 index;/** HARTs assigned to this domain */
include/sbi/sbi_domain_data.h deleted +0 -93
93 lines not on this page · raw message
include/sbi/sbi_domain_state.h new file +93 -0
93 lines not on this page · raw message
lib/sbi/objects.mk +1 -1
@@ -68,7 +68,7 @@ libsbi-objs-y += sbi_bitmap.o libsbi-objs-y += sbi_bitops.o libsbi-objs-y += sbi_console.o libsbi-objs-y += sbi_domain_context.o -libsbi-objs-y += sbi_domain_data.o +libsbi-objs-y += sbi_domain_state.o libsbi-objs-y += sbi_domain.o libsbi-objs-y += sbi_double_trap.o libsbi-objs-y += sbi_emulate_csr.o
lib/sbi/sbi_domain.c +3 -3
@@ -687,10 +687,10 @@ int sbi_domain_register(struct sbi_domain *dom, } } -/* Setup data for the discovered domain */ - rc =sbi_domain_setup_data (dom); +/* Setup state for the discovered domain */ + rc =sbi_domain_setup_state (dom);if (rc) { -sbi_printf ("%s: domain data setup failed for %s (error %d)\n" , +sbi_printf ("%s: domain state setup failed for %s (error %d)\n" , __func__, dom->name, rc);sbi_list_del (&dom->node);return rc;
lib/sbi/sbi_domain_context.c +7 -7
@@ -64,14 +64,14 @@ struct hart_context {bool initialized; }; -static struct sbi_domain_data dcpriv; +static struct sbi_domain_state dcstate;static inline struct hart_context *hart_context_get (struct sbi_domain *dom,u32 hartindex) {struct hart_context **dom_hartindex_to_context_table; - dom_hartindex_to_context_table =sbi_domain_data_ptr (dom, &dcpriv); + dom_hartindex_to_context_table =sbi_domain_state_ptr (dom, &dcstate);if (!dom_hartindex_to_context_table || !sbi_hartindex_valid (hartindex))return NULL ;
@@ -83,7 +83,7 @@ static void hart_context_set(struct sbi_domain *dom, u32 hartindex, {struct hart_context **dom_hartindex_to_context_table; - dom_hartindex_to_context_table =sbi_domain_data_ptr (dom, &dcpriv); + dom_hartindex_to_context_table =sbi_domain_state_ptr (dom, &dcstate);if (!dom_hartindex_to_context_table || !sbi_hartindex_valid (hartindex))return ;
@@ -314,15 +314,15 @@ int sbi_domain_context_init(void)/** * Allocate per-domain and per-hart context data. * The data type is "struct hart_context **" whose memory space will be -* dynamically allocated by domain_setup_data_one(). Calculate needed +* dynamically allocated by domain_setup_state_one(). Calculate needed * size of memory space here. */ - dcpriv.data_size =sizeof (struct hart_context *) *sbi_hart_count (); + dcstate.state_size =sizeof (struct hart_context *) *sbi_hart_count (); -return sbi_domain_register_data (&dcpriv); +return sbi_domain_register_state (&dcstate); }void sbi_domain_context_deinit (void ) { -sbi_domain_unregister_data (&dcpriv); +sbi_domain_unregister_state (&dcstate); }
lib/sbi/sbi_domain_data.c deleted +0 -138
138 lines not on this page · raw message
lib/sbi/sbi_domain_state.c new file +138 -0
138 lines not on this page · raw message
lib/sbi/sbi_mpxy.c +16 -16
@@ -267,11 +267,11 @@ int sbi_mpxy_register_channel(struct sbi_mpxy_channel *channel) }/** Setup per domain MPXY state data */ -static int domain_mpxy_state_data_setup (struct sbi_domain *dom, -struct sbi_domain_data *data, -void *data_ptr) +static int domain_mpxy_state_setup (struct sbi_domain *dom, +struct sbi_domain_state *state, +void *state_ptr) { -struct mpxy_state **dom_hartindex_to_mpxy_state_table = data_ptr; +struct mpxy_state **dom_hartindex_to_mpxy_state_table = state_ptr;struct mpxy_state *ms;u32 i;
@@ -296,20 +296,20 @@ static int domain_mpxy_state_data_setup(struct sbi_domain *dom, }/** Cleanup per domain MPXY state data */ -static void domain_mpxy_state_data_cleanup (struct sbi_domain *dom, -struct sbi_domain_data *data, -void *data_ptr) +static void domain_mpxy_state_cleanup (struct sbi_domain *dom, +struct sbi_domain_state *state, +void *state_ptr) { -struct mpxy_state **dom_hartindex_to_mpxy_state_table = data_ptr; +struct mpxy_state **dom_hartindex_to_mpxy_state_table = state_ptr;u32 i;sbi_hartmask_for_each_hartindex (i, dom->possible_harts)sbi_free (dom_hartindex_to_mpxy_state_table[i]); } -static struct sbi_domain_data dmspriv = { - .data_setup = domain_mpxy_state_data_setup, - .data_cleanup = domain_mpxy_state_data_cleanup, +static struct sbi_domain_state dmstate = { + .state_setup = domain_mpxy_state_setup, + .state_cleanup = domain_mpxy_state_cleanup, };/**
@@ -324,7 +324,7 @@ static struct mpxy_state *sbi_domain_get_mpxy_state(struct sbi_domain *dom, {struct mpxy_state **dom_hartindex_to_mpxy_state_table; - dom_hartindex_to_mpxy_state_table =sbi_domain_data_ptr (dom, &dmspriv); + dom_hartindex_to_mpxy_state_table =sbi_domain_state_ptr (dom, &dmstate);if (!dom_hartindex_to_mpxy_state_table || !sbi_hartindex_valid (hartindex))return NULL ;
@@ -339,12 +339,12 @@ int sbi_mpxy_init(struct sbi_scratch *scratch)/** * Allocate per-domain and per-hart MPXY state data. * The data type is "struct mpxy_state **" whose memory space will be -* dynamically allocated by domain_setup_data_one() and -* domain_mpxy_state_data_setup(). Calculate needed size of memory space +* dynamically allocated by domain_setup_state_one() and +* domain_mpxy_state_setup(). Calculate needed size of memory space * here. */ - dmspriv.data_size =sizeof (struct mpxy_state *) *sbi_hart_count (); - ret =sbi_domain_register_data (&dmspriv); + dmstate.state_size =sizeof (struct mpxy_state *) *sbi_hart_count (); + ret =sbi_domain_register_state (&dmstate);if (ret)return ret;
Signature · 7 lines
2.53.0 -- opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
Re: [PATCH 2/2] lib: sbi_domain: Rename per-domain data to per-domain state
Quoted 10 lines · Rahul Pathak
The per-domain
sbi_domain_datahold each domain associated state like hart context insbi_domain_context, mpxy state insbi_mpxy, and others like each domain backed by the corresponding MPT (SMMPT).
DATA reads as a generic name, while every use stores state. Rename functions and macros appropriately. There are no functional changes.Signed-off-by Rahul Pathak <[email protected]>
LGTM.
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
Quoted 689 lines
--- include/sbi/sbi_domain.h | 6 +- include/sbi/sbi_domain_data.h | 93 ---------------------- include/sbi/sbi_domain_state.h | 93 ++++++++++++++++++++++ lib/sbi/objects.mk | 2 +- lib/sbi/sbi_domain.c | 6 +- lib/sbi/sbi_domain_context.c | 14 ++-- lib/sbi/sbi_domain_data.c | 138 --------------------------------- lib/sbi/sbi_domain_state.c | 138 +++++++++++++++++++++++++++++++++ lib/sbi/sbi_mpxy.c | 32 ++++---- 9 files changed, 261 insertions(+), 261 deletions(-) delete mode 100644 include/sbi/sbi_domain_data.h create mode 100644 include/sbi/sbi_domain_state.h delete mode 100644 lib/sbi/sbi_domain_data.c create mode 100644 lib/sbi/sbi_domain_state.cinclude/sbi/sbi_domain.h +3
-3@@ -15,7 +15,7 @@#include <sbi/sbi_types.h> #include <sbi/sbi_hartmask.h> #include <sbi/sbi_domain_context.h> -#include <sbi/sbi_domain_data.h> +#include <sbi/sbi_domain_state.h> struct sbi_scratch ;@@ -189,8 +189,8 @@ static inline bool sbi_domain_memregion_is_subset(struct sbi_domain {/** Node in linked list of domains */ struct sbi_dlist node; -/** Internal state of per-domain data */ -struct sbi_domain_data_priv data_priv; +/** Internal per-domain state areas */ +struct sbi_domain_state_priv state_priv;/** Logical index of this domain */ u32 index;/** HARTs assigned to this domain */ include/sbi/sbi_domain_data.h deleted +0
-93@@ -1,93 +0,0 @@ -/* -* SPDX-License-Identifier: BSD-2-Clause -* -* Copyright (c) 2024 Ventana Micro Systems Inc. -*/ - -#ifndef __SBI_DOMAIN_DATA_H__ -#define __SBI_DOMAIN_DATA_H__ - -#include <sbi/sbi_types.h> -#include <sbi/sbi_list.h> - -struct sbi_domain ; - -/** Maximum domain data per-domain */ -#define SBI_DOMAIN_MAX_DATA_PTRS 32 - -/** Representation of per-domain data */ -struct sbi_domain_data_priv { -/** Array of domain data pointers indexed by domain data identifier */ -void *idx_to_data_ptr[SBI_DOMAIN_MAX_DATA_PTRS ]; -}; - -/** Representation of a domain data */ -struct sbi_domain_data { -/** -* Head is used for maintaining data list -* -* Note: initialized by domain framework -*/ -struct sbi_dlist head; -/** -* Identifier which used to locate per-domain data -* -* Note: initialized by domain framework -*/ -unsigned long data_idx; -/** Size of per-domain data */ -unsigned long data_size; -/** Optional callback to setup domain data */ -int (*data_setup)(struct sbi_domain *dom, -struct sbi_domain_data *data,void *data_ptr); -/** Optional callback to cleanup domain data */ -void (*data_cleanup)(struct sbi_domain *dom, -struct sbi_domain_data *data,void *data_ptr); -}; - -/** -* Get per-domain data pointer for a given domain -* @param dom pointer to domain -* @param data pointer to domain data -* -* @return per-domain data pointer -*/ -void *sbi_domain_data_ptr (struct sbi_domain *dom,struct sbi_domain_data *data); - -/** -* Setup all domain data for a domain -* @param dom pointer to domain -* -* @return 0 on success and negative error code on failure -* -* Note: This function is used internally within domain framework. -*/ -int sbi_domain_setup_data (struct sbi_domain *dom); - -/** -* Cleanup all domain data for a domain -* @param dom pointer to domain -* -* Note: This function is used internally within domain framework. -*/ -void sbi_domain_cleanup_data (struct sbi_domain *dom); - -/** -* Register a domain data -* @param hndl pointer to domain data -* -* @return 0 on success and negative error code on failure -* -* Note: This function must be used only in cold boot path. -*/ -int sbi_domain_register_data (struct sbi_domain_data *data); - -/** -* Unregister a domain data -* @param hndl pointer to domain data -* -* Note: This function must be used only in cold boot path. -*/ -void sbi_domain_unregister_data (struct sbi_domain_data *data); - -#endif include/sbi/sbi_domain_state.h new file +93
-0@@ -0,0 +1,93 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2024 Ventana Micro Systems Inc. +*/ + +#ifndef __SBI_DOMAIN_STATE_H__ +#define __SBI_DOMAIN_STATE_H__ + +#include <sbi/sbi_types.h> +#include <sbi/sbi_list.h> + +struct sbi_domain ; + +/** Maximum number of per-domain state areas */ +#define SBI_DOMAIN_MAX_STATE_PTRS 32 + +/** Internal per-domain state areas */ +struct sbi_domain_state_priv { +/** Array of per-domain state pointers indexed by state identifier */ +void *idx_to_state_ptr[SBI_DOMAIN_MAX_STATE_PTRS ]; +}; + +/** Representation of a domain state */ +struct sbi_domain_state { +/** +* Head is used for maintaining state list +* +* Note: initialized by domain framework +*/ +struct sbi_dlist head; +/** +* Identifier which used to locate per-domain state +* +* Note: initialized by domain framework +*/ +unsigned long state_idx; +/** Size of per-domain state */ +unsigned long state_size; +/** Optional callback to setup domain state */ +int (*state_setup)(struct sbi_domain *dom, +struct sbi_domain_state *state,void *state_ptr); +/** Optional callback to cleanup domain state */ +void (*state_cleanup)(struct sbi_domain *dom, +struct sbi_domain_state *state,void *state_ptr); +}; + +/** +* Get per-domain state pointer for a given domain +* @param dom pointer to domain +* @param state pointer to domain state +* +* @return per-domain state pointer +*/ +void *sbi_domain_state_ptr (struct sbi_domain *dom,struct sbi_domain_state *state); + +/** +* Setup all domain state for a domain +* @param dom pointer to domain +* +* @return 0 on success and negative error code on failure +* +* Note: This function is used internally within domain framework. +*/ +int sbi_domain_setup_state (struct sbi_domain *dom); + +/** +* Cleanup all domain state for a domain +* @param dom pointer to domain +* +* Note: This function is used internally within domain framework. +*/ +void sbi_domain_cleanup_state (struct sbi_domain *dom); + +/** +* Register a domain state +* @param hndl pointer to domain state +* +* @return 0 on success and negative error code on failure +* +* Note: This function must be used only in cold boot path. +*/ +int sbi_domain_register_state (struct sbi_domain_state *state); + +/** +* Unregister a domain state +* @param hndl pointer to domain state +* +* Note: This function must be used only in cold boot path. +*/ +void sbi_domain_unregister_state (struct sbi_domain_state *state); + +#endif lib/sbi/objects.mk +1
-1@@ -68,7 +68,7 @@ libsbi-objs-y += sbi_bitmap.o libsbi-objs-y += sbi_bitops.o libsbi-objs-y += sbi_console.o libsbi-objs-y += sbi_domain_context.o -libsbi-objs-y += sbi_domain_data.o +libsbi-objs-y += sbi_domain_state.o libsbi-objs-y += sbi_domain.o libsbi-objs-y += sbi_double_trap.o libsbi-objs-y += sbi_emulate_csr.olib/sbi/sbi_domain.c +3
-3@@ -687,10 +687,10 @@ int sbi_domain_register(struct sbi_domain *dom, } } -/* Setup data for the discovered domain */ - rc =sbi_domain_setup_data (dom); +/* Setup state for the discovered domain */ + rc =sbi_domain_setup_state (dom);if (rc) { -sbi_printf ("%s: domain data setup failed for %s (error %d)\n" , +sbi_printf ("%s: domain state setup failed for %s (error %d)\n" , __func__, dom->name, rc);sbi_list_del (&dom->node);return rc;lib/sbi/sbi_domain_context.c +7
-7@@ -64,14 +64,14 @@ struct hart_context {bool initialized; }; -static struct sbi_domain_data dcpriv; +static struct sbi_domain_state dcstate;static inline struct hart_context *hart_context_get (struct sbi_domain *dom,u32 hartindex) {struct hart_context **dom_hartindex_to_context_table; - dom_hartindex_to_context_table =sbi_domain_data_ptr (dom, &dcpriv); + dom_hartindex_to_context_table =sbi_domain_state_ptr (dom, &dcstate);if (!dom_hartindex_to_context_table || !sbi_hartindex_valid (hartindex))return NULL ;@@ -83,7 +83,7 @@ static void hart_context_set(struct sbi_domain *dom, u32 hartindex, {struct hart_context **dom_hartindex_to_context_table; - dom_hartindex_to_context_table =sbi_domain_data_ptr (dom, &dcpriv); + dom_hartindex_to_context_table =sbi_domain_state_ptr (dom, &dcstate);if (!dom_hartindex_to_context_table || !sbi_hartindex_valid (hartindex))return ;@@ -314,15 +314,15 @@ int sbi_domain_context_init(void)/** * Allocate per-domain and per-hart context data. * The data type is "struct hart_context **" whose memory space will be -* dynamically allocated by domain_setup_data_one(). Calculate needed +* dynamically allocated by domain_setup_state_one(). Calculate needed * size of memory space here. */ - dcpriv.data_size =sizeof (struct hart_context *) *sbi_hart_count (); + dcstate.state_size =sizeof (struct hart_context *) *sbi_hart_count (); -return sbi_domain_register_data (&dcpriv); +return sbi_domain_register_state (&dcstate); }void sbi_domain_context_deinit (void ) { -sbi_domain_unregister_data (&dcpriv); +sbi_domain_unregister_state (&dcstate); }lib/sbi/sbi_domain_data.c deleted +0
-138@@ -1,138 +0,0 @@ -/* -* SPDX-License-Identifier: BSD-2-Clause -* -* Copyright (c) 2024 Ventana Micro Systems Inc. -*/ - -#include <sbi/sbi_bitmap.h> -#include <sbi/sbi_domain.h> -#include <sbi/sbi_error.h> -#include <sbi/sbi_heap.h> - -static SBI_LIST_HEAD (data_list); -static DECLARE_BITMAP(data_idx_bmap, SBI_DOMAIN_MAX_DATA_PTRS); - -void *sbi_domain_data_ptr (struct sbi_domain *dom,struct sbi_domain_data *data) -{ -if (dom && data && data->data_idx <SBI_DOMAIN_MAX_DATA_PTRS ) -return dom->data_priv.idx_to_data_ptr[data->data_idx]; - -return NULL ; -} - -static int domain_setup_data_one (struct sbi_domain *dom, -struct sbi_domain_data *data) -{ -struct sbi_domain_data_priv *priv = &dom->data_priv; -void *data_ptr; -int rc; - -if (priv->idx_to_data_ptr[data->data_idx]) -return SBI_EALREADY ; - - data_ptr =sbi_zalloc (data->data_size); -if (!data_ptr) { -sbi_domain_cleanup_data (dom); -return SBI_ENOMEM ; - } - -if (data->data_setup) { - rc = data->data_setup (dom, data, data_ptr); -if (rc) { -sbi_free (data_ptr); -return rc; - } - } - - priv->idx_to_data_ptr[data->data_idx] = data_ptr; -return 0 ; -} - -static void domain_cleanup_data_one (struct sbi_domain *dom, -struct sbi_domain_data *data) -{ -struct sbi_domain_data_priv *priv = &dom->data_priv; -void *data_ptr; - - data_ptr = priv->idx_to_data_ptr[data->data_idx]; -if (!data_ptr) -return ; - -if (data->data_cleanup) - data->data_cleanup (dom, data, data_ptr); - -sbi_free (data_ptr); - priv->idx_to_data_ptr[data->data_idx] =NULL ; -} - -int sbi_domain_setup_data (struct sbi_domain *dom) -{ -struct sbi_domain_data *data; -int rc; - -if (!dom) -return SBI_EINVAL ; - -sbi_list_for_each_entry (data, &data_list, head) { - rc =domain_setup_data_one (dom, data); -if (rc) { -sbi_domain_cleanup_data (dom); -return rc; - } - } - -return 0 ; -} - -void sbi_domain_cleanup_data (struct sbi_domain *dom) -{ -struct sbi_domain_data *data; - -if (!dom) -return ; - -sbi_list_for_each_entry (data, &data_list, head) -domain_cleanup_data_one (dom, data); -} - -int sbi_domain_register_data (struct sbi_domain_data *data) -{ -struct sbi_domain *dom; -u32 data_idx; -int rc; - -if (!data || !data->data_size) -return SBI_EINVAL ; - -for (data_idx =0 ; data_idx <SBI_DOMAIN_MAX_DATA_PTRS ; data_idx++) { -if (!bitmap_test (data_idx_bmap, data_idx)) -break ; - } -if (SBI_DOMAIN_MAX_DATA_PTRS <= data_idx) -return SBI_ENOSPC ; -bitmap_set (data_idx_bmap, data_idx,1 ); - - data->data_idx = data_idx; -sbi_list_add_tail (&data->head, &data_list); - -sbi_domain_for_each (dom) { - rc =domain_setup_data_one (dom, data); -if (rc) { -sbi_domain_unregister_data (data); -return rc; - } - } - -return 0 ; -} - -void sbi_domain_unregister_data (struct sbi_domain_data *data) -{ -struct sbi_domain *dom; - -sbi_domain_for_each (dom) -domain_cleanup_data_one (dom, data); - -sbi_list_del (&data->head); -bitmap_clear (data_idx_bmap, data->data_idx,1 ); -}lib/sbi/sbi_domain_state.c new file +138
-0@@ -0,0 +1,138 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2024 Ventana Micro Systems Inc. +*/ + +#include <sbi/sbi_bitmap.h> +#include <sbi/sbi_domain.h> +#include <sbi/sbi_error.h> +#include <sbi/sbi_heap.h> + +static SBI_LIST_HEAD (state_list); +static DECLARE_BITMAP(state_idx_bmap, SBI_DOMAIN_MAX_STATE_PTRS); + +void *sbi_domain_state_ptr (struct sbi_domain *dom,struct sbi_domain_state *state) +{ +if (dom && state && state->state_idx <SBI_DOMAIN_MAX_STATE_PTRS ) +return dom->state_priv.idx_to_state_ptr[state->state_idx]; + +return NULL ; +} + +static int domain_setup_state_one (struct sbi_domain *dom, +struct sbi_domain_state *state) +{ +struct sbi_domain_state_priv *priv = &dom->state_priv; +void *state_ptr; +int rc; + +if (priv->idx_to_state_ptr[state->state_idx]) +return SBI_EALREADY ; + + state_ptr =sbi_zalloc (state->state_size); +if (!state_ptr) { +sbi_domain_cleanup_state (dom); +return SBI_ENOMEM ; + } + +if (state->state_setup) { + rc = state->state_setup (dom, state, state_ptr); +if (rc) { +sbi_free (state_ptr); +return rc; + } + } + + priv->idx_to_state_ptr[state->state_idx] = state_ptr; +return 0 ; +} + +static void domain_cleanup_state_one (struct sbi_domain *dom, +struct sbi_domain_state *state) +{ +struct sbi_domain_state_priv *priv = &dom->state_priv; +void *state_ptr; + + state_ptr = priv->idx_to_state_ptr[state->state_idx]; +if (!state_ptr) +return ; + +if (state->state_cleanup) + state->state_cleanup (dom, state, state_ptr); + +sbi_free (state_ptr); + priv->idx_to_state_ptr[state->state_idx] =NULL ; +} + +int sbi_domain_setup_state (struct sbi_domain *dom) +{ +struct sbi_domain_state *state; +int rc; + +if (!dom) +return SBI_EINVAL ; + +sbi_list_for_each_entry (state, &state_list, head) { + rc =domain_setup_state_one (dom, state); +if (rc) { +sbi_domain_cleanup_state (dom); +return rc; + } + } + +return 0 ; +} + +void sbi_domain_cleanup_state (struct sbi_domain *dom) +{ +struct sbi_domain_state *state; + +if (!dom) +return ; + +sbi_list_for_each_entry (state, &state_list, head) +domain_cleanup_state_one (dom, state); +} + +int sbi_domain_register_state (struct sbi_domain_state *state) +{ +struct sbi_domain *dom; +u32 state_idx; +int rc; + +if (!state || !state->state_size) +return SBI_EINVAL ; + +for (state_idx =0 ; state_idx <SBI_DOMAIN_MAX_STATE_PTRS ; state_idx++) { +if (!bitmap_test (state_idx_bmap, state_idx)) +break ; + } +if (SBI_DOMAIN_MAX_STATE_PTRS <= state_idx) +return SBI_ENOSPC ; +bitmap_set (state_idx_bmap, state_idx,1 ); + + state->state_idx = state_idx; +sbi_list_add_tail (&state->head, &state_list); + +sbi_domain_for_each (dom) { + rc =domain_setup_state_one (dom, state); +if (rc) { +sbi_domain_unregister_state (state); +return rc; + } + } + +return 0 ; +} + +void sbi_domain_unregister_state (struct sbi_domain_state *state) +{ +struct sbi_domain *dom; + +sbi_domain_for_each (dom) +domain_cleanup_state_one (dom, state); + +sbi_list_del (&state->head); +bitmap_clear (state_idx_bmap, state->state_idx,1 ); +}lib/sbi/sbi_mpxy.c +16
-17@@ -267,11 +267,11 @@ int sbi_mpxy_register_channel(struct sbi_mpxy_channel *channel) }/** Setup per domain MPXY state data */ -static int domain_mpxy_state_data_setup (struct sbi_domain *dom, -struct sbi_domain_data *data, -void *data_ptr) +static int domain_mpxy_state_setup (struct sbi_domain *dom, +struct sbi_domain_state *state, +void *state_ptr) { -struct mpxy_state **dom_hartindex_to_mpxy_state_table = data_ptr; +struct mpxy_state **dom_hartindex_to_mpxy_state_table = state_ptr;struct mpxy_state *ms;u32 i;@@ -296,20 +296,20 @@ static int domain_mpxy_state_data_setup(struct sbi_domain *dom, }/** Cleanup per domain MPXY state data */ -static void domain_mpxy_state_data_cleanup (struct sbi_domain *dom, -struct sbi_domain_data *data, -void *data_ptr) +static void domain_mpxy_state_cleanup (struct sbi_domain *dom, +struct sbi_domain_state *state, +void *state_ptr) { -struct mpxy_state **dom_hartindex_to_mpxy_state_table = data_ptr; +struct mpxy_state **dom_hartindex_to_mpxy_state_table = state_ptr;u32 i;sbi_hartmask_for_each_hartindex (i, dom->possible_harts)sbi_free (dom_hartindex_to_mpxy_state_table[i]); } -static struct sbi_domain_data dmspriv = { - .data_setup = domain_mpxy_state_data_setup, - .data_cleanup = domain_mpxy_state_data_cleanup, +static struct sbi_domain_state dmstate = { + .state_setup = domain_mpxy_state_setup, + .state_cleanup = domain_mpxy_state_cleanup, };/** @@ -324,7 +324,7 @@ static struct mpxy_state *sbi_domain_get_mpxy_state(struct sbi_domain *dom, {struct mpxy_state **dom_hartindex_to_mpxy_state_table; - dom_hartindex_to_mpxy_state_table =sbi_domain_data_ptr (dom, &dmspriv); + dom_hartindex_to_mpxy_state_table =sbi_domain_state_ptr (dom, &dmstate);if (!dom_hartindex_to_mpxy_state_table || !sbi_hartindex_valid (hartindex))return NULL ;@@ -339,12 +339,12 @@ int sbi_mpxy_init(struct sbi_scratch *scratch)/** * Allocate per-domain and per-hart MPXY state data. * The data type is "struct mpxy_state **" whose memory space will be -* dynamically allocated by domain_setup_data_one() and -* domain_mpxy_state_data_setup(). Calculate needed size of memory space +* dynamically allocated by domain_setup_state_one() and +* domain_mpxy_state_setup(). Calculate needed size of memory space * here. */ - dmspriv.data_size =sizeof (struct mpxy_state *) *sbi_hart_count (); - ret =sbi_domain_register_data (&dmspriv); + dmstate.state_size =sizeof (struct mpxy_state *) *sbi_hart_count (); + ret =sbi_domain_register_state (&dmstate);if (ret)return ret; --2.53.0
--
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
Signature · 3 lines
opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi