Debian Codegraph @

src/lib/bmp_logo.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <acpi/acpi.h>
4 #include <bootsplash.h>
5 #include <cbfs.h>
6 #include <cbmem.h>
7 #include <stdint.h>
8 #include <vendorcode/google/chromeos/chromeos.h>
9
10 static const struct cbmem_entry *logo_entry;
11
12 /* Mapping of different bootsplash logo name based on bootsplash type */
13 static const char *bootsplash_list[BOOTSPLASH_MAX_NUM] = {
14 [BOOTSPLASH_LOW_BATTERY] = "low_battery.bmp",
15 [BOOTSPLASH_CENTER] = "logo.bmp",
16 [BOOTSPLASH_FOOTER] = "footer_logo.bmp"
17 };
18
19 /*
20 * Return the appropriate logo filename based on the bootsplash type.
21 * This will be the default filename from 'bootsplash_list' or the
22 * custom one if it was overridden for BOOTSPLASH_OEM.
23 */
24 static const char *bmp_get_logo_filename(enum bootsplash_type type)
25 {
26 /* Override `BOOTSPLASH_CENTER` logo name if required */
27 if ((type == BOOTSPLASH_CENTER) && CONFIG(HAVE_CUSTOM_BMP_LOGO))
28 return bmp_logo_filename();
29
30 return bootsplash_list[type];
31 }
32
33 void *bmp_load_logo_by_type(enum bootsplash_type type, size_t *logo_size)
34 {
35 void *logo_buffer;
36
37 /* CBMEM is locked for S3 resume path. */
38 if (acpi_is_wakeup_s3())
39 return NULL;
40
41 logo_entry = cbmem_entry_add(CBMEM_ID_BMP_LOGO, 1 * MiB);
42 if (!logo_entry)
43 return NULL;
44
45 logo_buffer = cbmem_entry_start(logo_entry);
46 if (!logo_buffer)
47 return NULL;
48
49 *logo_size = cbfs_load(bmp_get_logo_filename(type), logo_buffer, 1 * MiB);
50 if (*logo_size == 0)
51 return NULL;
52
53 return logo_buffer;
54 }
55
56 void *bmp_load_logo(size_t *logo_size)
57 {
58 enum bootsplash_type type = BOOTSPLASH_CENTER;
59
60 if (platform_is_low_battery_shutdown_needed())
61 type = BOOTSPLASH_LOW_BATTERY;
62
63 return bmp_load_logo_by_type(type, logo_size);
64 }
65
66 void bmp_release_logo(void)
67 {
68 if (logo_entry)
69 cbmem_entry_remove(logo_entry);
70 logo_entry = NULL;
71 }