hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/scripts/mod/file2alias.c
....@@ -36,7 +36,16 @@
3636 typedef unsigned char __u8;
3737 typedef struct {
3838 __u8 b[16];
39
+} guid_t;
40
+
41
+/* backwards compatibility, don't use in new code */
42
+typedef struct {
43
+ __u8 b[16];
3944 } uuid_le;
45
+typedef struct {
46
+ __u8 b[16];
47
+} uuid_t;
48
+#define UUID_STRING_LEN 36
4049
4150 /* Big exception to the "don't include kernel headers into userspace, which
4251 * even potentially has different endianness and word sizes, since
....@@ -50,17 +59,28 @@
5059 int (*do_entry)(const char *filename, void *symval, char *alias);
5160 };
5261
62
+/* Size of alias provided to do_entry functions */
63
+#define ALIAS_SIZE 500
64
+
5365 /* Define a variable f that holds the value of field f of struct devid
5466 * based at address m.
5567 */
5668 #define DEF_FIELD(m, devid, f) \
5769 typeof(((struct devid *)0)->f) f = TO_NATIVE(*(typeof(f) *)((m) + OFF_##devid##_##f))
70
+
71
+/* Define a variable v that holds the address of field f of struct devid
72
+ * based at address m. Due to the way typeof works, for a field of type
73
+ * T[N] the variable has type T(*)[N], _not_ T*.
74
+ */
75
+#define DEF_FIELD_ADDR_VAR(m, devid, f, v) \
76
+ typeof(((struct devid *)0)->f) *v = ((m) + OFF_##devid##_##f)
77
+
5878 /* Define a variable f that holds the address of field f of struct devid
5979 * based at address m. Due to the way typeof works, for a field of type
6080 * T[N] the variable has type T(*)[N], _not_ T*.
6181 */
6282 #define DEF_FIELD_ADDR(m, devid, f) \
63
- typeof(((struct devid *)0)->f) *f = ((m) + OFF_##devid##_##f)
83
+ DEF_FIELD_ADDR_VAR(m, devid, f, f)
6484
6585 #define ADD(str, sep, cond, field) \
6686 do { \
....@@ -586,7 +606,7 @@
586606
587607 for (i = 0; i < count; i++) {
588608 unsigned int j;
589
- DEF_FIELD_ADDR(symval + i*id_size, pnp_card_device_id, devs);
609
+ DEF_FIELD_ADDR(symval + i * id_size, pnp_card_device_id, devs);
590610
591611 for (j = 0; j < PNP_MAX_DEVICES; j++) {
592612 const char *id = (char *)(*devs)[j].id;
....@@ -598,10 +618,13 @@
598618
599619 /* find duplicate, already added value */
600620 for (i2 = 0; i2 < i && !dup; i2++) {
601
- DEF_FIELD_ADDR(symval + i2*id_size, pnp_card_device_id, devs);
621
+ DEF_FIELD_ADDR_VAR(symval + i2 * id_size,
622
+ pnp_card_device_id,
623
+ devs, devs_dup);
602624
603625 for (j2 = 0; j2 < PNP_MAX_DEVICES; j2++) {
604
- const char *id2 = (char *)(*devs)[j2].id;
626
+ const char *id2 =
627
+ (char *)(*devs_dup)[j2].id;
605628
606629 if (!id2[0])
607630 break;
....@@ -896,6 +919,24 @@
896919 return 1;
897920 }
898921
922
+static int do_i3c_entry(const char *filename, void *symval,
923
+ char *alias)
924
+{
925
+ DEF_FIELD(symval, i3c_device_id, match_flags);
926
+ DEF_FIELD(symval, i3c_device_id, dcr);
927
+ DEF_FIELD(symval, i3c_device_id, manuf_id);
928
+ DEF_FIELD(symval, i3c_device_id, part_id);
929
+ DEF_FIELD(symval, i3c_device_id, extra_info);
930
+
931
+ strcpy(alias, "i3c:");
932
+ ADD(alias, "dcr", match_flags & I3C_MATCH_DCR, dcr);
933
+ ADD(alias, "manuf", match_flags & I3C_MATCH_MANUF, manuf_id);
934
+ ADD(alias, "part", match_flags & I3C_MATCH_PART, part_id);
935
+ ADD(alias, "ext", match_flags & I3C_MATCH_EXTRA_INFO, extra_info);
936
+
937
+ return 1;
938
+}
939
+
899940 /* Looks like: spi:S */
900941 static int do_spi_entry(const char *filename, void *symval,
901942 char *alias)
....@@ -913,6 +954,8 @@
913954 { "bvn", DMI_BIOS_VENDOR },
914955 { "bvr", DMI_BIOS_VERSION },
915956 { "bd", DMI_BIOS_DATE },
957
+ { "br", DMI_BIOS_RELEASE },
958
+ { "efr", DMI_EC_FIRMWARE_RELEASE },
916959 { "svn", DMI_SYS_VENDOR },
917960 { "pn", DMI_PRODUCT_NAME },
918961 { "pvr", DMI_PRODUCT_VERSION },
....@@ -1215,15 +1258,19 @@
12151258 return 1;
12161259 }
12171260
1218
-/* Looks like: sdw:mNpN */
1261
+/* Looks like: sdw:mNpNvNcN */
12191262 static int do_sdw_entry(const char *filename, void *symval, char *alias)
12201263 {
12211264 DEF_FIELD(symval, sdw_device_id, mfg_id);
12221265 DEF_FIELD(symval, sdw_device_id, part_id);
1266
+ DEF_FIELD(symval, sdw_device_id, sdw_version);
1267
+ DEF_FIELD(symval, sdw_device_id, class_id);
12231268
12241269 strcpy(alias, "sdw:");
12251270 ADD(alias, "m", mfg_id != 0, mfg_id);
12261271 ADD(alias, "p", part_id != 0, part_id);
1272
+ ADD(alias, "v", sdw_version != 0, sdw_version);
1273
+ ADD(alias, "c", class_id != 0, class_id);
12271274
12281275 add_wildcard(alias);
12291276 return 1;
....@@ -1276,6 +1323,51 @@
12761323 return 1;
12771324 }
12781325
1326
+/* Looks like: tee:uuid */
1327
+static int do_tee_entry(const char *filename, void *symval, char *alias)
1328
+{
1329
+ DEF_FIELD(symval, tee_client_device_id, uuid);
1330
+
1331
+ sprintf(alias, "tee:%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1332
+ uuid.b[0], uuid.b[1], uuid.b[2], uuid.b[3], uuid.b[4],
1333
+ uuid.b[5], uuid.b[6], uuid.b[7], uuid.b[8], uuid.b[9],
1334
+ uuid.b[10], uuid.b[11], uuid.b[12], uuid.b[13], uuid.b[14],
1335
+ uuid.b[15]);
1336
+
1337
+ add_wildcard(alias);
1338
+ return 1;
1339
+}
1340
+
1341
+/* Looks like: wmi:guid */
1342
+static int do_wmi_entry(const char *filename, void *symval, char *alias)
1343
+{
1344
+ int len;
1345
+ DEF_FIELD_ADDR(symval, wmi_device_id, guid_string);
1346
+
1347
+ if (strlen(*guid_string) != UUID_STRING_LEN) {
1348
+ warn("Invalid WMI device id 'wmi:%s' in '%s'\n",
1349
+ *guid_string, filename);
1350
+ return 0;
1351
+ }
1352
+
1353
+ len = snprintf(alias, ALIAS_SIZE, WMI_MODULE_PREFIX "%s", *guid_string);
1354
+ if (len < 0 || len >= ALIAS_SIZE) {
1355
+ warn("Could not generate all MODULE_ALIAS's in '%s'\n",
1356
+ filename);
1357
+ return 0;
1358
+ }
1359
+ return 1;
1360
+}
1361
+
1362
+/* Looks like: mhi:S */
1363
+static int do_mhi_entry(const char *filename, void *symval, char *alias)
1364
+{
1365
+ DEF_FIELD_ADDR(symval, mhi_device_id, chan);
1366
+ sprintf(alias, MHI_DEVICE_MODALIAS_FMT, *chan);
1367
+
1368
+ return 1;
1369
+}
1370
+
12791371 /* Does namelen bytes of name exactly match the symbol? */
12801372 static bool sym_is(const char *name, unsigned namelen, const char *symbol)
12811373 {
....@@ -1292,7 +1384,7 @@
12921384 struct module *mod)
12931385 {
12941386 unsigned int i;
1295
- char alias[500];
1387
+ char alias[ALIAS_SIZE];
12961388
12971389 device_id_check(mod->name, device_id, size, id_size, symval);
12981390 /* Leave last one: it's the terminator. */
....@@ -1327,6 +1419,7 @@
13271419 {"vmbus", SIZE_hv_vmbus_device_id, do_vmbus_entry},
13281420 {"rpmsg", SIZE_rpmsg_device_id, do_rpmsg_entry},
13291421 {"i2c", SIZE_i2c_device_id, do_i2c_entry},
1422
+ {"i3c", SIZE_i3c_device_id, do_i3c_entry},
13301423 {"spi", SIZE_spi_device_id, do_spi_entry},
13311424 {"dmi", SIZE_dmi_system_id, do_dmi_entry},
13321425 {"platform", SIZE_platform_device_id, do_platform_entry},
....@@ -1346,6 +1439,9 @@
13461439 {"fslmc", SIZE_fsl_mc_device_id, do_fsl_mc_entry},
13471440 {"tbsvc", SIZE_tb_service_id, do_tbsvc_entry},
13481441 {"typec", SIZE_typec_device_id, do_typec_entry},
1442
+ {"tee", SIZE_tee_client_device_id, do_tee_entry},
1443
+ {"wmi", SIZE_wmi_device_id, do_wmi_entry},
1444
+ {"mhi", SIZE_mhi_device_id, do_mhi_entry},
13491445 };
13501446
13511447 /* Create MODULE_ALIAS() statements.
....@@ -1367,11 +1463,10 @@
13671463 if (ELF_ST_TYPE(sym->st_info) != STT_OBJECT)
13681464 return;
13691465
1370
- /* All our symbols are of form <prefix>__mod_<name>__<identifier>_device_table. */
1371
- name = strstr(symname, "__mod_");
1372
- if (!name)
1466
+ /* All our symbols are of form __mod_<name>__<identifier>_device_table. */
1467
+ if (strncmp(symname, "__mod_", strlen("__mod_")))
13731468 return;
1374
- name += strlen("__mod_");
1469
+ name = symname + strlen("__mod_");
13751470 namelen = strlen(name);
13761471 if (namelen < strlen("_device_table"))
13771472 return;
....@@ -1395,7 +1490,7 @@
13951490 /* First handle the "special" cases */
13961491 if (sym_is(name, namelen, "usb"))
13971492 do_usb_table(symval, sym->st_size, mod);
1398
- if (sym_is(name, namelen, "of"))
1493
+ else if (sym_is(name, namelen, "of"))
13991494 do_of_table(symval, sym->st_size, mod);
14001495 else if (sym_is(name, namelen, "pnp"))
14011496 do_pnp_device_entry(symval, sym->st_size, mod);