blob: 7e03e0c9392b49331d75e4902a06733e8aff9473 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Heinrich Schuchardt2a6daf72017-10-05 16:36:07 +02002/*
3 * efi_selftest_util
4 *
5 * Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk@gmx.de>
6 *
Heinrich Schuchardt2a6daf72017-10-05 16:36:07 +02007 * Utility functions
8 */
9
10#include <efi_selftest.h>
11
Heinrich Schuchardt9cda2ef2018-09-11 22:38:04 +020012struct efi_st_translate {
13 u16 code;
14 u16 *text;
15};
16
17static struct efi_st_translate efi_st_control_characters[] = {
Simon Glass90975372022-01-23 12:55:12 -070018 {0, u"Null"},
19 {8, u"BS"},
20 {9, u"TAB"},
21 {10, u"LF"},
22 {13, u"CR"},
Heinrich Schuchardt9cda2ef2018-09-11 22:38:04 +020023 {0, NULL},
24};
25
Simon Glass90975372022-01-23 12:55:12 -070026static u16 efi_st_ch[] = u"' '";
27static u16 efi_st_unknown[] = u"unknown";
Heinrich Schuchardt9cda2ef2018-09-11 22:38:04 +020028
29static struct efi_st_translate efi_st_scan_codes[] = {
Simon Glass90975372022-01-23 12:55:12 -070030 {0x00, u"Null"},
31 {0x01, u"Up"},
32 {0x02, u"Down"},
33 {0x03, u"Right"},
34 {0x04, u"Left"},
35 {0x05, u"Home"},
36 {0x06, u"End"},
37 {0x07, u"Insert"},
38 {0x08, u"Delete"},
39 {0x09, u"Page Up"},
40 {0x0a, u"Page Down"},
41 {0x0b, u"FN 1"},
42 {0x0c, u"FN 2"},
43 {0x0d, u"FN 3"},
44 {0x0e, u"FN 4"},
45 {0x0f, u"FN 5"},
46 {0x10, u"FN 6"},
47 {0x11, u"FN 7"},
48 {0x12, u"FN 8"},
49 {0x13, u"FN 9"},
50 {0x14, u"FN 10"},
51 {0x15, u"FN 11"},
52 {0x16, u"FN 12"},
53 {0x17, u"Escape"},
54 {0x68, u"FN 13"},
55 {0x69, u"FN 14"},
56 {0x6a, u"FN 15"},
57 {0x6b, u"FN 16"},
58 {0x6c, u"FN 17"},
59 {0x6d, u"FN 18"},
60 {0x6e, u"FN 19"},
61 {0x6f, u"FN 20"},
62 {0x70, u"FN 21"},
63 {0x71, u"FN 22"},
64 {0x72, u"FN 23"},
65 {0x73, u"FN 24"},
66 {0x7f, u"Mute"},
67 {0x80, u"Volume Up"},
68 {0x81, u"Volume Down"},
69 {0x100, u"Brightness Up"},
70 {0x101, u"Brightness Down"},
71 {0x102, u"Suspend"},
72 {0x103, u"Hibernate"},
73 {0x104, u"Toggle Display"},
74 {0x105, u"Recovery"},
75 {0x106, u"Reject"},
Heinrich Schuchardt9cda2ef2018-09-11 22:38:04 +020076 {0x0, NULL},
77};
78
79u16 *efi_st_translate_char(u16 code)
80{
81 struct efi_st_translate *tr;
82
83 if (code >= ' ') {
84 efi_st_ch[1] = code;
85 return efi_st_ch;
86 }
87 for (tr = efi_st_control_characters; tr->text; ++tr) {
88 if (tr->code == code)
89 return tr->text;
90 }
91 return efi_st_unknown;
92}
93
94u16 *efi_st_translate_code(u16 code)
95{
96 struct efi_st_translate *tr;
97
98 for (tr = efi_st_scan_codes; tr->text; ++tr) {
99 if (tr->code == code)
100 return tr->text;
101 }
102 return efi_st_unknown;
103}
104
Heinrich Schuchardt02efd5d2017-10-18 18:13:13 +0200105int efi_st_strcmp_16_8(const u16 *buf1, const char *buf2)
106{
107 for (; *buf1 || *buf2; ++buf1, ++buf2) {
108 if (*buf1 != *buf2)
109 return *buf1 - *buf2;
110 }
111 return 0;
112}
Heinrich Schuchardt135b42f2022-09-03 15:56:51 +0200113
114void *efi_st_get_config_table(const efi_guid_t *guid)
115{
116 size_t i;
117
118 for (i = 0; i < st_systable->nr_tables; i++) {
119 if (!guidcmp(guid, &st_systable->tables[i].guid))
120 return st_systable->tables[i].table;
121 }
122 return NULL;
123}