1 /*
2 * Copyright (c) 2020 Texas Instruments Incorporated - https://www.ti.com
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * * Neither the name of Texas Instruments Incorporated nor the names of
16 * its contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 */
33 #include <errno.h>
34 #include <stdio.h>
35 #include <stdbool.h>
36 #include <sys/types.h>
37 #include <dirent.h>
38 #include <string.h>
39 #include <fcntl.h>
40 #include <unistd.h>
42 #include "rpmsg_char_internal.h"
44 /* Increment this whenever new SoC data is added */
45 #define NUM_SOC_FAMILY 3
47 struct soc_data {
48 const char *family_name;
49 const struct rproc_map *map;
50 int num_rprocs;
51 };
53 /* TI K3 AM65x SoCs */
54 const struct rproc_map am65x_map[] = {
55 { .id = R5F_MCU0_0, .rproc_name = "41000000.r5f", },
56 { .id = R5F_MCU0_1, .rproc_name = "41400000.r5f", },
57 };
59 /* TI K3 J721E SoCs */
60 const struct rproc_map j721e_map[] = {
61 { .id = R5F_MCU0_0, .rproc_name = "41000000.r5f", },
62 { .id = R5F_MCU0_1, .rproc_name = "41400000.r5f", },
63 { .id = R5F_MAIN0_0, .rproc_name = "5c00000.r5f", },
64 { .id = R5F_MAIN0_1, .rproc_name = "5d00000.r5f", },
65 { .id = R5F_MAIN1_0, .rproc_name = "5e00000.r5f", },
66 { .id = R5F_MAIN1_1, .rproc_name = "5f00000.r5f", },
67 { .id = DSP_C66_0, .rproc_name = "4d80800000.dsp", },
68 { .id = DSP_C66_1, .rproc_name = "4d81800000.dsp", },
69 { .id = DSP_C71_0, .rproc_name = "64800000.dsp", },
70 };
72 /* TI K3 J7200 SoCs */
73 const struct rproc_map j7200_map[] = {
74 { .id = R5F_MCU0_0, .rproc_name = "41000000.r5f", },
75 { .id = R5F_MCU0_1, .rproc_name = "41400000.r5f", },
76 { .id = R5F_MAIN0_0, .rproc_name = "5c00000.r5f", },
77 { .id = R5F_MAIN0_1, .rproc_name = "5d00000.r5f", },
78 };
80 const struct soc_data socs[NUM_SOC_FAMILY] = {
81 {
82 .family_name = "AM65X",
83 .map = am65x_map,
84 .num_rprocs = (sizeof(am65x_map) / sizeof(struct rproc_map)),
85 },
86 {
87 .family_name = "J721E",
88 .map = j721e_map,
89 .num_rprocs = (sizeof(j721e_map) / sizeof(struct rproc_map)),
90 },
91 {
92 .family_name = "J7200",
93 .map = j7200_map,
94 .num_rprocs = (sizeof(j7200_map) / sizeof(struct rproc_map)),
95 },
96 };
98 int _rpmsg_char_find_soc_family(const char *name, struct soc_rprocs *soc)
99 {
100 int ret, i;
101 char family_name[32];
102 bool found = false;
104 if (check_dir("/sys/devices/soc0")) {
105 fprintf(stderr, "Kernel doesn't have a soc device, use fallback detection..\n");
106 goto fallback;
107 }
109 ret = file_read_string("/sys/devices/soc0/family", family_name,
110 sizeof(family_name));
111 if (ret < 0)
112 return -ENOENT;
114 for (i = 0; i < NUM_SOC_FAMILY; i++) {
115 if (!strcmp(family_name, socs[i].family_name)) {
116 found = true;
117 break;
118 }
119 }
121 fallback:
122 /* fall back to using passed in SoC family name */
123 if (!found && name) {
124 for (i = 0; i < NUM_SOC_FAMILY; i++) {
125 if (!strcmp(name, socs[i].family_name)) {
126 found = true;
127 break;
128 }
129 }
130 }
132 if (!found) {
133 fprintf(stderr, "%s: SoC device family match failed\n", __func__);
134 return -ENOENT;
135 }
137 soc->num_rprocs = socs[i].num_rprocs;
138 soc->map = socs[i].map;
140 return 0;
141 }