linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] MIPS: octeon: Get rid of preprocessor directives around RESERVE32
@ 2022-09-06  7:52 Alexander A Sverdlin
  2022-09-06  8:09 ` Yu Zhao
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander A Sverdlin @ 2022-09-06  7:52 UTC (permalink / raw)
  To: Yu Zhao, Joe Perches, Thomas Bogendoerfer, linux-mips, Corey Minyard
  Cc: Alexander Sverdlin, linux-kernel

From: Alexander Sverdlin <alexander.sverdlin@nokia.com>

Some of them were pointless because CONFIG_CAVIUM_RESERVE32 is now always
defined, some were not enough (Yu Zhao reported [1]
"Failed to allocate CAVIUM_RESERVE32 memory area" error).

Removing (in contrast to proposal [2] though) the directives allows for
compiler coverage of RESERVE32 code and replacing one of [always-true]
"ifdef" with a compiler conditional fixes the [cosmetic] error message.

Couple of variables doesn't justify preprocessor ugliness and none of this
code is in a hot-path.

Link: https://lore.kernel.org/lkml/20220830030259.3503212-1-yuzhao@google.com/
Link: https://lore.kernel.org/lkml/d5f8d6b58a32cdbf6326ccef7d46a58ba753edc7.camel@perches.com/
Signed-off-by: Alexander Sverdlin <alexander.sverdlin@nokia.com>
---
 arch/mips/cavium-octeon/executive/cvmx-cmd-queue.c |  4 ----
 arch/mips/cavium-octeon/setup.c                    | 25 +++++++++-------------
 2 files changed, 10 insertions(+), 19 deletions(-)

diff --git a/arch/mips/cavium-octeon/executive/cvmx-cmd-queue.c b/arch/mips/cavium-octeon/executive/cvmx-cmd-queue.c
index bf13e35..aa7bbf8 100644
--- a/arch/mips/cavium-octeon/executive/cvmx-cmd-queue.c
+++ b/arch/mips/cavium-octeon/executive/cvmx-cmd-queue.c
@@ -57,14 +57,11 @@ EXPORT_SYMBOL_GPL(__cvmx_cmd_queue_state_ptr);
 static cvmx_cmd_queue_result_t __cvmx_cmd_queue_init_state_ptr(void)
 {
 	char *alloc_name = "cvmx_cmd_queues";
-#if defined(CONFIG_CAVIUM_RESERVE32) && CONFIG_CAVIUM_RESERVE32
 	extern uint64_t octeon_reserve32_memory;
-#endif
 
 	if (likely(__cvmx_cmd_queue_state_ptr))
 		return CVMX_CMD_QUEUE_SUCCESS;
 
-#if defined(CONFIG_CAVIUM_RESERVE32) && CONFIG_CAVIUM_RESERVE32
 	if (octeon_reserve32_memory)
 		__cvmx_cmd_queue_state_ptr =
 		    cvmx_bootmem_alloc_named_range(sizeof(*__cvmx_cmd_queue_state_ptr),
@@ -73,7 +70,6 @@ static cvmx_cmd_queue_result_t __cvmx_cmd_queue_init_state_ptr(void)
 						   (CONFIG_CAVIUM_RESERVE32 <<
 						    20) - 1, 128, alloc_name);
 	else
-#endif
 		__cvmx_cmd_queue_state_ptr =
 		    cvmx_bootmem_alloc_named(sizeof(*__cvmx_cmd_queue_state_ptr),
 					    128,
diff --git a/arch/mips/cavium-octeon/setup.c b/arch/mips/cavium-octeon/setup.c
index cbd8320..df45f76 100644
--- a/arch/mips/cavium-octeon/setup.c
+++ b/arch/mips/cavium-octeon/setup.c
@@ -284,10 +284,8 @@ void octeon_crash_smp_send_stop(void)
 
 #endif /* CONFIG_KEXEC */
 
-#ifdef CONFIG_CAVIUM_RESERVE32
 uint64_t octeon_reserve32_memory;
 EXPORT_SYMBOL(octeon_reserve32_memory);
-#endif
 
 #ifdef CONFIG_KEXEC
 /* crashkernel cmdline parameter is parsed _after_ memory setup
@@ -666,9 +664,7 @@ void __init prom_init(void)
 	int i;
 	u64 t;
 	int argc;
-#ifdef CONFIG_CAVIUM_RESERVE32
 	int64_t addr = -1;
-#endif
 	/*
 	 * The bootloader passes a pointer to the boot descriptor in
 	 * $a3, this is available as fw_arg3.
@@ -783,7 +779,7 @@ void __init prom_init(void)
 		cvmx_write_csr(CVMX_LED_UDD_DATX(1), 0);
 		cvmx_write_csr(CVMX_LED_EN, 1);
 	}
-#ifdef CONFIG_CAVIUM_RESERVE32
+
 	/*
 	 * We need to temporarily allocate all memory in the reserve32
 	 * region. This makes sure the kernel doesn't allocate this
@@ -794,14 +790,15 @@ void __init prom_init(void)
 	 * Allocate memory for RESERVED32 aligned on 2MB boundary. This
 	 * is in case we later use hugetlb entries with it.
 	 */
-	addr = cvmx_bootmem_phy_named_block_alloc(CONFIG_CAVIUM_RESERVE32 << 20,
-						0, 0, 2 << 20,
-						"CAVIUM_RESERVE32", 0);
-	if (addr < 0)
-		pr_err("Failed to allocate CAVIUM_RESERVE32 memory area\n");
-	else
-		octeon_reserve32_memory = addr;
-#endif
+	if (CONFIG_CAVIUM_RESERVE32) {
+		addr = cvmx_bootmem_phy_named_block_alloc(CONFIG_CAVIUM_RESERVE32 << 20,
+							  0, 0, 2 << 20,
+							  "CAVIUM_RESERVE32", 0);
+		if (addr < 0)
+			pr_err("Failed to allocate CAVIUM_RESERVE32 memory area\n");
+		else
+			octeon_reserve32_memory = addr;
+	}
 
 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2
 	if (cvmx_read_csr(CVMX_L2D_FUS3) & (3ull << 34)) {
@@ -1079,7 +1076,6 @@ void __init plat_mem_setup(void)
 	cvmx_bootmem_unlock();
 #endif /* CONFIG_CRASH_DUMP */
 
-#ifdef CONFIG_CAVIUM_RESERVE32
 	/*
 	 * Now that we've allocated the kernel memory it is safe to
 	 * free the reserved region. We free it here so that builtin
@@ -1087,7 +1083,6 @@ void __init plat_mem_setup(void)
 	 */
 	if (octeon_reserve32_memory)
 		cvmx_bootmem_free_named("CAVIUM_RESERVE32");
-#endif /* CONFIG_CAVIUM_RESERVE32 */
 
 	if (total == 0)
 		panic("Unable to allocate memory from "
-- 
2.10.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] MIPS: octeon: Get rid of preprocessor directives around RESERVE32
  2022-09-06  7:52 [PATCH] MIPS: octeon: Get rid of preprocessor directives around RESERVE32 Alexander A Sverdlin
@ 2022-09-06  8:09 ` Yu Zhao
  0 siblings, 0 replies; 2+ messages in thread
From: Yu Zhao @ 2022-09-06  8:09 UTC (permalink / raw)
  To: Alexander A Sverdlin
  Cc: Joe Perches, Thomas Bogendoerfer, linux-mips, Corey Minyard,
	linux-kernel

On Tue, Sep 6, 2022 at 1:53 AM Alexander A Sverdlin
<alexander.sverdlin@nokia.com> wrote:
>
> From: Alexander Sverdlin <alexander.sverdlin@nokia.com>
>
> Some of them were pointless because CONFIG_CAVIUM_RESERVE32 is now always
> defined, some were not enough (Yu Zhao reported [1]
> "Failed to allocate CAVIUM_RESERVE32 memory area" error).
>
> Removing (in contrast to proposal [2] though) the directives allows for
> compiler coverage of RESERVE32 code and replacing one of [always-true]
> "ifdef" with a compiler conditional fixes the [cosmetic] error message.
>
> Couple of variables doesn't justify preprocessor ugliness and none of this
> code is in a hot-path.
>
> Link: https://lore.kernel.org/lkml/20220830030259.3503212-1-yuzhao@google.com/
> Link: https://lore.kernel.org/lkml/d5f8d6b58a32cdbf6326ccef7d46a58ba753edc7.camel@perches.com/
> Signed-off-by: Alexander Sverdlin <alexander.sverdlin@nokia.com>
> ---
>  arch/mips/cavium-octeon/executive/cvmx-cmd-queue.c |  4 ----
>  arch/mips/cavium-octeon/setup.c                    | 25 +++++++++-------------
>  2 files changed, 10 insertions(+), 19 deletions(-)
>
> diff --git a/arch/mips/cavium-octeon/executive/cvmx-cmd-queue.c b/arch/mips/cavium-octeon/executive/cvmx-cmd-queue.c
> index bf13e35..aa7bbf8 100644
> --- a/arch/mips/cavium-octeon/executive/cvmx-cmd-queue.c
> +++ b/arch/mips/cavium-octeon/executive/cvmx-cmd-queue.c
> @@ -57,14 +57,11 @@ EXPORT_SYMBOL_GPL(__cvmx_cmd_queue_state_ptr);
>  static cvmx_cmd_queue_result_t __cvmx_cmd_queue_init_state_ptr(void)
>  {
>         char *alloc_name = "cvmx_cmd_queues";
> -#if defined(CONFIG_CAVIUM_RESERVE32) && CONFIG_CAVIUM_RESERVE32
>         extern uint64_t octeon_reserve32_memory;
> -#endif
>
>         if (likely(__cvmx_cmd_queue_state_ptr))
>                 return CVMX_CMD_QUEUE_SUCCESS;
>
> -#if defined(CONFIG_CAVIUM_RESERVE32) && CONFIG_CAVIUM_RESERVE32
>         if (octeon_reserve32_memory)
>                 __cvmx_cmd_queue_state_ptr =
>                     cvmx_bootmem_alloc_named_range(sizeof(*__cvmx_cmd_queue_state_ptr),
> @@ -73,7 +70,6 @@ static cvmx_cmd_queue_result_t __cvmx_cmd_queue_init_state_ptr(void)
>                                                    (CONFIG_CAVIUM_RESERVE32 <<
>                                                     20) - 1, 128, alloc_name);
>         else
> -#endif
>                 __cvmx_cmd_queue_state_ptr =
>                     cvmx_bootmem_alloc_named(sizeof(*__cvmx_cmd_queue_state_ptr),
>                                             128,
> diff --git a/arch/mips/cavium-octeon/setup.c b/arch/mips/cavium-octeon/setup.c
> index cbd8320..df45f76 100644
> --- a/arch/mips/cavium-octeon/setup.c
> +++ b/arch/mips/cavium-octeon/setup.c
> @@ -284,10 +284,8 @@ void octeon_crash_smp_send_stop(void)
>
>  #endif /* CONFIG_KEXEC */
>
> -#ifdef CONFIG_CAVIUM_RESERVE32
>  uint64_t octeon_reserve32_memory;
>  EXPORT_SYMBOL(octeon_reserve32_memory);
> -#endif
>
>  #ifdef CONFIG_KEXEC
>  /* crashkernel cmdline parameter is parsed _after_ memory setup
> @@ -666,9 +664,7 @@ void __init prom_init(void)
>         int i;
>         u64 t;
>         int argc;
> -#ifdef CONFIG_CAVIUM_RESERVE32
>         int64_t addr = -1;
> -#endif

Nit: `addr` can be moved into the `if` block below.

>         /*
>          * The bootloader passes a pointer to the boot descriptor in
>          * $a3, this is available as fw_arg3.
> @@ -783,7 +779,7 @@ void __init prom_init(void)
>                 cvmx_write_csr(CVMX_LED_UDD_DATX(1), 0);
>                 cvmx_write_csr(CVMX_LED_EN, 1);
>         }
> -#ifdef CONFIG_CAVIUM_RESERVE32
> +
>         /*
>          * We need to temporarily allocate all memory in the reserve32
>          * region. This makes sure the kernel doesn't allocate this
> @@ -794,14 +790,15 @@ void __init prom_init(void)
>          * Allocate memory for RESERVED32 aligned on 2MB boundary. This
>          * is in case we later use hugetlb entries with it.
>          */
> -       addr = cvmx_bootmem_phy_named_block_alloc(CONFIG_CAVIUM_RESERVE32 << 20,
> -                                               0, 0, 2 << 20,
> -                                               "CAVIUM_RESERVE32", 0);
> -       if (addr < 0)
> -               pr_err("Failed to allocate CAVIUM_RESERVE32 memory area\n");
> -       else
> -               octeon_reserve32_memory = addr;
> -#endif
> +       if (CONFIG_CAVIUM_RESERVE32) {
> +               addr = cvmx_bootmem_phy_named_block_alloc(CONFIG_CAVIUM_RESERVE32 << 20,
> +                                                         0, 0, 2 << 20,
> +                                                         "CAVIUM_RESERVE32", 0);

I.e., `int64_t addr = cvmx_...`.

> +               if (addr < 0)
> +                       pr_err("Failed to allocate CAVIUM_RESERVE32 memory area\n");
> +               else
> +                       octeon_reserve32_memory = addr;
> +       }

Acked-by: Yu Zhao <yuzhao@google.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-06  8:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-06  7:52 [PATCH] MIPS: octeon: Get rid of preprocessor directives around RESERVE32 Alexander A Sverdlin
2022-09-06  8:09 ` Yu Zhao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).