[PATCH v6 14/44] x86/boot: introduce boot module interator

Daniel P. Smith posted 44 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH v6 14/44] x86/boot: introduce boot module interator
Posted by Daniel P. Smith 1 month, 1 week ago
Provide an iterator to go through boot module array searching based on type.

Signed-off-by: Daniel P. Smith <dpsmith@apertussolutions.com>
---
Changes since v5:
- documented help next_boot_module_index
- switch to unsigned int for next_boot_module_index
- changes identified that BOOTMOD_XEN was not supported, so added support
---
 xen/arch/x86/include/asm/bootinfo.h | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/xen/arch/x86/include/asm/bootinfo.h b/xen/arch/x86/include/asm/bootinfo.h
index 5862054b8cef..3010e6f4af9c 100644
--- a/xen/arch/x86/include/asm/bootinfo.h
+++ b/xen/arch/x86/include/asm/bootinfo.h
@@ -62,8 +62,35 @@ struct boot_info {
     struct boot_module mods[MAX_NR_BOOTMODS + 1];
 };
 
-#endif /* __XEN_X86_BOOTINFO_H__ */
+/*
+ * next_boot_module_index:
+ *     Finds the next boot module of type t, starting at array index start.
+ *
+ * Returns:
+ *      Success - index in boot_module array
+ *      Failure - a value greater than MAX_NR_BOOTMODS
+ */
+static inline unsigned int __init next_boot_module_index(
+    const struct boot_info *bi, enum bootmod_type t, unsigned int start)
+{
+    unsigned int i;
+
+    if ( t == BOOTMOD_XEN )
+        return MAX_NR_BOOTMODS;
 
+    for ( i = start; i < bi->nr_modules; i++ )
+    {
+        if ( bi->mods[i].type == t )
+            return i;
+    }
+
+    return MAX_NR_BOOTMODS + 1;
+}
+
+#define first_boot_module_index(bi, t)              \
+    next_boot_module_index(bi, t, 0)
+
+#endif /* __XEN_X86_BOOTINFO_H__ */
 /*
  * Local variables:
  * mode: C
-- 
2.30.2
Re: [PATCH v6 14/44] x86/boot: introduce boot module interator
Posted by Jason Andryuk 1 month, 1 week ago
On 2024-10-17 13:02, Daniel P. Smith wrote:
> Provide an iterator to go through boot module array searching based on type.
> 
> Signed-off-by: Daniel P. Smith <dpsmith@apertussolutions.com>
> ---
> Changes since v5:
> - documented help next_boot_module_index
> - switch to unsigned int for next_boot_module_index
> - changes identified that BOOTMOD_XEN was not supported, so added support
> ---
>   xen/arch/x86/include/asm/bootinfo.h | 29 ++++++++++++++++++++++++++++-
>   1 file changed, 28 insertions(+), 1 deletion(-)
> 
> diff --git a/xen/arch/x86/include/asm/bootinfo.h b/xen/arch/x86/include/asm/bootinfo.h
> index 5862054b8cef..3010e6f4af9c 100644
> --- a/xen/arch/x86/include/asm/bootinfo.h
> +++ b/xen/arch/x86/include/asm/bootinfo.h
> @@ -62,8 +62,35 @@ struct boot_info {
>       struct boot_module mods[MAX_NR_BOOTMODS + 1];
>   };
>   
> -#endif /* __XEN_X86_BOOTINFO_H__ */
> +/*
> + * next_boot_module_index:
> + *     Finds the next boot module of type t, starting at array index start.
> + *
> + * Returns:
> + *      Success - index in boot_module array
> + *      Failure - a value greater than MAX_NR_BOOTMODS
> + */
> +static inline unsigned int __init next_boot_module_index(
> +    const struct boot_info *bi, enum bootmod_type t, unsigned int start)
> +{
> +    unsigned int i;
> +
> +    if ( t == BOOTMOD_XEN )
> +        return MAX_NR_BOOTMODS;

Your earlier patch "x86/boot: convert mod refs to boot_module mod" put 
xen at bi->nr_modules.  You'll want these to match.

Regards,
Jason

>   
> +    for ( i = start; i < bi->nr_modules; i++ )
> +    {
> +        if ( bi->mods[i].type == t )
> +            return i;
> +    }
> +
> +    return MAX_NR_BOOTMODS + 1;
> +}
> +
> +#define first_boot_module_index(bi, t)              \
> +    next_boot_module_index(bi, t, 0)
> +
> +#endif /* __XEN_X86_BOOTINFO_H__ */
>   /*
>    * Local variables:
>    * mode: C
Re: [PATCH v6 14/44] x86/boot: introduce boot module interator
Posted by Daniel P. Smith 1 month ago
On 10/18/24 10:09, Jason Andryuk wrote:
> On 2024-10-17 13:02, Daniel P. Smith wrote:
>> Provide an iterator to go through boot module array searching based on 
>> type.
>>
>> Signed-off-by: Daniel P. Smith <dpsmith@apertussolutions.com>
>> ---
>> Changes since v5:
>> - documented help next_boot_module_index
>> - switch to unsigned int for next_boot_module_index
>> - changes identified that BOOTMOD_XEN was not supported, so added support
>> ---
>>   xen/arch/x86/include/asm/bootinfo.h | 29 ++++++++++++++++++++++++++++-
>>   1 file changed, 28 insertions(+), 1 deletion(-)
>>
>> diff --git a/xen/arch/x86/include/asm/bootinfo.h 
>> b/xen/arch/x86/include/asm/bootinfo.h
>> index 5862054b8cef..3010e6f4af9c 100644
>> --- a/xen/arch/x86/include/asm/bootinfo.h
>> +++ b/xen/arch/x86/include/asm/bootinfo.h
>> @@ -62,8 +62,35 @@ struct boot_info {
>>       struct boot_module mods[MAX_NR_BOOTMODS + 1];
>>   };
>> -#endif /* __XEN_X86_BOOTINFO_H__ */
>> +/*
>> + * next_boot_module_index:
>> + *     Finds the next boot module of type t, starting at array index 
>> start.
>> + *
>> + * Returns:
>> + *      Success - index in boot_module array
>> + *      Failure - a value greater than MAX_NR_BOOTMODS
>> + */
>> +static inline unsigned int __init next_boot_module_index(
>> +    const struct boot_info *bi, enum bootmod_type t, unsigned int start)
>> +{
>> +    unsigned int i;
>> +
>> +    if ( t == BOOTMOD_XEN )
>> +        return MAX_NR_BOOTMODS;
> 
> Your earlier patch "x86/boot: convert mod refs to boot_module mod" put 
> xen at bi->nr_modules.  You'll want these to match.

Yep.

v/r,
dps