lib: sbi: Print scratch size and usage at boot time
authorAnup Patel <apatel@ventanamicro.com>
Thu, 20 Apr 2023 08:32:37 +0000 (14:02 +0530)
committerAnup Patel <anup@brainfault.org>
Mon, 5 Jun 2023 10:16:22 +0000 (15:46 +0530)
The scratch space being a scarce resource so let us print it's
size and usage at boot time.

Signed-off-by: Anup Patel <apatel@ventanamicro.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
include/sbi/sbi_scratch.h
lib/sbi/sbi_init.c
lib/sbi/sbi_scratch.c

index 9894c704757803586121cdc4d09edb4854f2de1a..48014923e36f211f0bb40a91da7d17d663b47ef1 100644 (file)
@@ -175,6 +175,9 @@ unsigned long sbi_scratch_alloc_offset(unsigned long size);
 /** Free-up extra space in sbi_scratch */
 void sbi_scratch_free_offset(unsigned long offset);
 
+/** Amount (in bytes) of used space in in sbi_scratch */
+unsigned long sbi_scratch_used_space(void);
+
 /** Get pointer from offset in sbi_scratch */
 #define sbi_scratch_offset_ptr(scratch, offset)        (void *)((char *)(scratch) + (offset))
 
index a1705254d9deea7ecc4d3fe62fbaea3c528e5cf3..423e6d83650f98becd39b22ab22820704e21d6b9 100644 (file)
@@ -128,6 +128,11 @@ static void sbi_boot_print_general(struct sbi_scratch *scratch)
                   (u32)(sbi_heap_reserved_space() / 1024),
                   (u32)(sbi_heap_used_space() / 1024),
                   (u32)(sbi_heap_free_space() / 1024));
+       sbi_printf("Firmware Scratch Size     : "
+                  "%d B (total), %d B (used), %d B (free)\n",
+                  SBI_SCRATCH_SIZE,
+                  (u32)sbi_scratch_used_space(),
+                  (u32)(SBI_SCRATCH_SIZE - sbi_scratch_used_space()));
 
        /* SBI details */
        sbi_printf("Runtime SBI Version       : %d.%d\n",
index 55ebdbb76a8ecc8c82f80b5b4bbc2c03eb4851f6..87ef84cafd31cbfbb26646b3b2ec2a08192f5e3e 100644 (file)
@@ -97,3 +97,14 @@ void sbi_scratch_free_offset(unsigned long offset)
         * brain-dead allocator.
         */
 }
+
+unsigned long sbi_scratch_used_space(void)
+{
+       unsigned long ret = 0;
+
+       spin_lock(&extra_lock);
+       ret = extra_offset;
+       spin_unlock(&extra_lock);
+
+       return ret;
+}