Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1 | #include <stdbool.h> |
| 2 | #include <stdint.h> |
| 3 | #include <stdio.h> |
| 4 | #include <string.h> |
| 5 | |
| 6 | #include <arm/android/api.h> |
| 7 | #include <log.h> |
| 8 | |
| 9 | |
| 10 | #define CPUINFO_COUNT_OF(x) (sizeof(x) / sizeof(0[x])) |
| 11 | |
| 12 | |
| 13 | static inline bool is_ascii_whitespace(char c) { |
| 14 | switch (c) { |
| 15 | case ' ': |
| 16 | case '\t': |
| 17 | case '\r': |
| 18 | case '\n': |
| 19 | return true; |
| 20 | default: |
| 21 | return false; |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | static inline bool is_ascii_alphabetic(char c) { |
| 26 | const char lower_c = c | '\x20'; |
| 27 | return (uint8_t) (lower_c - 'a') <= (uint8_t) ('z' - 'a'); |
| 28 | } |
| 29 | |
| 30 | static inline bool is_ascii_alphabetic_uppercase(char c) { |
| 31 | return (uint8_t) (c - 'A') <= (uint8_t) ('Z' - 'A'); |
| 32 | } |
| 33 | |
| 34 | static inline bool is_ascii_numeric(char c) { |
| 35 | return (uint8_t) (c - '0') < 10; |
| 36 | } |
| 37 | |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 38 | static inline uint16_t load_u16le(const void* ptr) { |
| 39 | #if defined(__ARM_ARCH_7A__) || defined(__aarch64__) |
| 40 | return *((const uint16_t*) ptr); |
| 41 | #else |
| 42 | const uint8_t* byte_ptr = (const uint8_t*) ptr; |
| 43 | return ((uint16_t) byte_ptr[1] << 8) | (uint16_t) byte_ptr[0]; |
| 44 | #endif |
| 45 | } |
| 46 | |
| 47 | static inline uint32_t load_u24le(const void* ptr) { |
| 48 | #if defined(__ARM_ARCH_7A__) || defined(__aarch64__) |
| 49 | return ((uint32_t) ((const uint8_t*) ptr)[2] << 16) | ((uint32_t) *((const uint16_t*) ptr)); |
| 50 | #else |
| 51 | const uint8_t* byte_ptr = (const uint8_t*) ptr; |
| 52 | return ((uint32_t) byte_ptr[2] << 16) | ((uint32_t) byte_ptr[1] << 8) | (uint32_t) byte_ptr[0]; |
| 53 | #endif |
| 54 | } |
| 55 | |
| 56 | static inline uint32_t load_u32le(const void* ptr) { |
| 57 | #if defined(__ARM_ARCH_7A__) || defined(__aarch64__) |
| 58 | return *((const uint32_t*) ptr); |
| 59 | #else |
| 60 | return ((uint32_t) ((const uint8_t*) ptr)[3] << 24) | load_u24le(ptr); |
| 61 | #endif |
| 62 | } |
| 63 | |
| 64 | /* |
| 65 | * Map from ARM chipset series ID to ARM chipset vendor ID. |
| 66 | * This map is used to avoid storing vendor IDs in tables. |
| 67 | */ |
| 68 | static enum cpuinfo_arm_chipset_vendor chipset_series_vendor[cpuinfo_arm_chipset_series_max] = { |
| 69 | [cpuinfo_arm_chipset_series_unknown] = cpuinfo_arm_chipset_vendor_unknown, |
| 70 | [cpuinfo_arm_chipset_series_qualcomm_qsd] = cpuinfo_arm_chipset_vendor_qualcomm, |
| 71 | [cpuinfo_arm_chipset_series_qualcomm_msm] = cpuinfo_arm_chipset_vendor_qualcomm, |
| 72 | [cpuinfo_arm_chipset_series_qualcomm_apq] = cpuinfo_arm_chipset_vendor_qualcomm, |
| 73 | [cpuinfo_arm_chipset_series_qualcomm_snapdragon] = cpuinfo_arm_chipset_vendor_qualcomm, |
| 74 | [cpuinfo_arm_chipset_series_mediatek_mt] = cpuinfo_arm_chipset_vendor_mediatek, |
| 75 | [cpuinfo_arm_chipset_series_samsung_exynos] = cpuinfo_arm_chipset_vendor_samsung, |
| 76 | [cpuinfo_arm_chipset_series_hisilicon_k3v] = cpuinfo_arm_chipset_vendor_hisilicon, |
| 77 | [cpuinfo_arm_chipset_series_hisilicon_hi] = cpuinfo_arm_chipset_vendor_hisilicon, |
| 78 | [cpuinfo_arm_chipset_series_hisilicon_kirin] = cpuinfo_arm_chipset_vendor_hisilicon, |
| 79 | [cpuinfo_arm_chipset_series_actions_atm] = cpuinfo_arm_chipset_vendor_actions, |
| 80 | [cpuinfo_arm_chipset_series_allwinner_a] = cpuinfo_arm_chipset_vendor_allwinner, |
| 81 | [cpuinfo_arm_chipset_series_amlogic_aml] = cpuinfo_arm_chipset_vendor_amlogic, |
| 82 | [cpuinfo_arm_chipset_series_amlogic_s] = cpuinfo_arm_chipset_vendor_amlogic, |
| 83 | [cpuinfo_arm_chipset_series_broadcom_bcm] = cpuinfo_arm_chipset_vendor_broadcom, |
| 84 | [cpuinfo_arm_chipset_series_lg_nuclun] = cpuinfo_arm_chipset_vendor_lg, |
| 85 | [cpuinfo_arm_chipset_series_leadcore_lc] = cpuinfo_arm_chipset_vendor_leadcore, |
| 86 | [cpuinfo_arm_chipset_series_marvell_pxa] = cpuinfo_arm_chipset_vendor_marvell, |
| 87 | [cpuinfo_arm_chipset_series_mstar_6a] = cpuinfo_arm_chipset_vendor_mstar, |
| 88 | [cpuinfo_arm_chipset_series_novathor_u] = cpuinfo_arm_chipset_vendor_novathor, |
| 89 | [cpuinfo_arm_chipset_series_nvidia_tegra_t] = cpuinfo_arm_chipset_vendor_nvidia, |
| 90 | [cpuinfo_arm_chipset_series_nvidia_tegra_ap] = cpuinfo_arm_chipset_vendor_nvidia, |
| 91 | [cpuinfo_arm_chipset_series_nvidia_tegra_sl] = cpuinfo_arm_chipset_vendor_nvidia, |
| 92 | [cpuinfo_arm_chipset_series_pinecone_surge_s] = cpuinfo_arm_chipset_vendor_pinecone, |
| 93 | [cpuinfo_arm_chipset_series_renesas_mp] = cpuinfo_arm_chipset_vendor_renesas, |
| 94 | [cpuinfo_arm_chipset_series_rockchip_rk] = cpuinfo_arm_chipset_vendor_rockchip, |
| 95 | [cpuinfo_arm_chipset_series_spreadtrum_sc] = cpuinfo_arm_chipset_vendor_spreadtrum, |
| 96 | [cpuinfo_arm_chipset_series_telechips_tcc] = cpuinfo_arm_chipset_vendor_telechips, |
| 97 | [cpuinfo_arm_chipset_series_texas_instruments_omap] = cpuinfo_arm_chipset_vendor_texas_instruments, |
| 98 | [cpuinfo_arm_chipset_series_wondermedia_wm] = cpuinfo_arm_chipset_vendor_wondermedia, |
| 99 | }; |
| 100 | |
| 101 | /** |
| 102 | * Tries to match /(MSM|APQ)\d{4}([A-Z\-]*)/ signature (case-insensitive) for Qualcomm MSM and APQ chipsets. |
| 103 | * If match successful, extracts model information into \p chipset argument. |
| 104 | * |
| 105 | * @param start - start of the platform identifier (/proc/cpuinfo Hardware string, ro.product.board, ro.board.platform |
| 106 | * or ro.chipname) to match. |
| 107 | * @param end - end of the platform identifier (/proc/cpuinfo Hardware string, ro.product.board, ro.board.platform or |
| 108 | * ro.chipname) to match. |
| 109 | * @param[out] chipset - location where chipset information will be stored upon a successful match. |
| 110 | * |
| 111 | * @returns true if signature matched, false otherwise. |
| 112 | */ |
| 113 | static bool match_msm_apq( |
| 114 | const char* start, const char* end, |
| 115 | struct cpuinfo_arm_chipset chipset[restrict static 1]) |
| 116 | { |
| 117 | /* Expect at least 7 symbols: 3 symbols "MSM" or "APQ" + 4 digits */ |
| 118 | if (start + 7 > end) { |
| 119 | return false; |
| 120 | } |
| 121 | |
| 122 | /* Check that string starts with "MSM" or "APQ", case-insensitive. |
| 123 | * The first three characters are loaded as 24-bit little endian word, binary ORed with 0x20 to convert to lower |
| 124 | * case, and compared to "MSM" and "APQ" strings as integers. |
| 125 | */ |
| 126 | const uint32_t series_signature = UINT32_C(0x00202020) | load_u24le(start); |
| 127 | enum cpuinfo_arm_chipset_series series; |
| 128 | switch (series_signature) { |
| 129 | case UINT32_C(0x6D736D): /* "msm" = reverse("msm") */ |
| 130 | series = cpuinfo_arm_chipset_series_qualcomm_msm; |
| 131 | break; |
| 132 | case UINT32_C(0x717061): /* "qpa" = reverse("apq") */ |
| 133 | series = cpuinfo_arm_chipset_series_qualcomm_apq; |
| 134 | break; |
| 135 | default: |
| 136 | return false; |
| 137 | } |
| 138 | |
| 139 | /* Sometimes there is a space ' ' following the MSM/APQ series */ |
| 140 | const char* pos = start + 3; |
| 141 | if (*pos == ' ') { |
| 142 | pos++; |
| 143 | |
| 144 | /* Expect at least 4 more symbols (4-digit model number) */ |
| 145 | if (pos + 4 > end) { |
| 146 | return false; |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | /* Validate and parse 4-digit model number */ |
| 151 | uint32_t model = 0; |
| 152 | for (uint32_t i = 0; i < 4; i++) { |
| 153 | const uint32_t digit = (uint32_t) (uint8_t) (*pos++) - '0'; |
| 154 | if (digit >= 10) { |
| 155 | /* Not really a digit */ |
| 156 | return false; |
| 157 | } |
| 158 | model = model * 10 + digit; |
| 159 | } |
| 160 | |
| 161 | /* Suffix is optional, so if we got to this point, parsing is successful. Commit parsed chipset. */ |
| 162 | *chipset = (struct cpuinfo_arm_chipset) { |
| 163 | .vendor = cpuinfo_arm_chipset_vendor_qualcomm, |
| 164 | .series = series, |
| 165 | .model = model, |
| 166 | }; |
| 167 | |
| 168 | /* Parse as many suffix characters as match the pattern [A-Za-z\-] */ |
| 169 | for (uint32_t i = 0; i < CPUINFO_ARM_CHIPSET_SUFFIX_MAX; i++) { |
| 170 | if (pos + i == end) { |
| 171 | break; |
| 172 | } |
| 173 | |
| 174 | const char c = pos[i]; |
| 175 | if (is_ascii_alphabetic(c)) { |
| 176 | /* Matched a letter [A-Za-z] */ |
| 177 | chipset->suffix[i] = c & '\xDF'; |
| 178 | } else if (c == '-') { |
| 179 | /* Matched a dash '-' */ |
| 180 | chipset->suffix[i] = c; |
| 181 | } else { |
| 182 | /* Neither of [A-Za-z\-] */ |
| 183 | break; |
| 184 | } |
| 185 | } |
| 186 | return true; |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * Tries to match /SDM\d{3}$/ signature for Qualcomm Snapdragon chipsets. |
| 191 | * If match successful, extracts model information into \p chipset argument. |
| 192 | * |
| 193 | * @param start - start of the /proc/cpuinfo Hardware string to match. |
| 194 | * @param end - end of the /proc/cpuinfo Hardware string to match. |
| 195 | * @param[out] chipset - location where chipset information will be stored upon a successful match. |
| 196 | * |
| 197 | * @returns true if signature matched, false otherwise. |
| 198 | */ |
| 199 | static bool match_sdm( |
| 200 | const char* start, const char* end, |
| 201 | struct cpuinfo_arm_chipset chipset[restrict static 1]) |
| 202 | { |
| 203 | /* Expect exactly 6 symbols: 3 symbols "SDM" + 3 digits */ |
| 204 | if (start + 6 != end) { |
| 205 | return false; |
| 206 | } |
| 207 | |
| 208 | /* Check that string starts with "SDM". |
| 209 | * The first three characters are loaded and compared as 24-bit little endian word. |
| 210 | */ |
| 211 | const uint32_t expected_sdm = load_u24le(start); |
| 212 | if (expected_sdm != UINT32_C(0x004D4453) /* "MDS" = reverse("SDM") */) { |
| 213 | return false; |
| 214 | } |
| 215 | |
| 216 | /* Validate and parse 3-digit model number */ |
| 217 | uint32_t model = 0; |
| 218 | for (uint32_t i = 3; i < 6; i++) { |
| 219 | const uint32_t digit = (uint32_t) (uint8_t) start[i] - '0'; |
| 220 | if (digit >= 10) { |
| 221 | /* Not really a digit */ |
| 222 | return false; |
| 223 | } |
| 224 | model = model * 10 + digit; |
| 225 | } |
| 226 | |
| 227 | /* Return parsed chipset. */ |
| 228 | *chipset = (struct cpuinfo_arm_chipset) { |
| 229 | .vendor = cpuinfo_arm_chipset_vendor_qualcomm, |
| 230 | .series = cpuinfo_arm_chipset_series_qualcomm_snapdragon, |
| 231 | .model = model, |
| 232 | }; |
| 233 | return true; |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * Tries to match /Samsung Exynos\d{4}$/ signature (case-insensitive) for Samsung Exynos chipsets. |
| 238 | * If match successful, extracts model information into \p chipset argument. |
| 239 | * |
| 240 | * @param start - start of the /proc/cpuinfo Hardware string to match. |
| 241 | * @param end - end of the /proc/cpuinfo Hardware string to match. |
| 242 | * @param[out] chipset - location where chipset information will be stored upon a successful match. |
| 243 | * |
| 244 | * @returns true if signature matched, false otherwise. |
| 245 | */ |
| 246 | static bool match_samsung_exynos( |
| 247 | const char* start, const char* end, |
| 248 | struct cpuinfo_arm_chipset chipset[restrict static 1]) |
| 249 | { |
| 250 | /* |
| 251 | * Expect at 18-19 symbols: |
| 252 | * - "Samsung" (7 symbols) + space + "Exynos" (6 symbols) + optional space 4-digit model number |
| 253 | */ |
| 254 | const size_t length = end - start; |
| 255 | switch (length) { |
| 256 | case 18: |
| 257 | case 19: |
| 258 | break; |
| 259 | default: |
| 260 | return false; |
| 261 | } |
| 262 | |
| 263 | /* |
| 264 | * Check that the string starts with "samsung exynos", case-insensitive. |
| 265 | * Blocks of 4 characters are loaded and compared as little-endian 32-bit word. |
| 266 | * Case-insensitive characters are binary ORed with 0x20 to convert them to lowercase. |
| 267 | */ |
| 268 | const uint32_t expected_sams = UINT32_C(0x20202000) | load_u32le(start); |
| 269 | if (expected_sams != UINT32_C(0x736D6153) /* "smaS" = reverse("Sams") */) { |
| 270 | return false; |
| 271 | } |
| 272 | const uint32_t expected_ung = UINT32_C(0x00202020) | load_u32le(start + 4); |
| 273 | if (expected_ung != UINT32_C(0x20676E75) /* " ung" = reverse("ung ") */) { |
| 274 | return false; |
| 275 | } |
| 276 | const uint32_t expected_exyn = UINT32_C(0x20202000) | load_u32le(start + 8); |
| 277 | if (expected_exyn != UINT32_C(0x6E797845) /* "nyxE" = reverse("Exyn") */) { |
| 278 | return false; |
| 279 | } |
| 280 | const uint16_t expected_os = UINT16_C(0x2020) | load_u16le(start + 12); |
| 281 | if (expected_os != UINT16_C(0x736F) /* "so" = reverse("os") */) { |
| 282 | return false; |
| 283 | } |
| 284 | |
| 285 | const char* pos = start + 14; |
| 286 | |
| 287 | /* There can be a space ' ' following the "Exynos" string */ |
| 288 | if (*pos == ' ') { |
| 289 | pos++; |
| 290 | |
| 291 | /* If optional space if present, we expect exactly 19 characters */ |
| 292 | if (length != 19) { |
| 293 | return false; |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | /* Validate and parse 4-digit model number */ |
| 298 | uint32_t model = 0; |
| 299 | for (uint32_t i = 0; i < 4; i++) { |
| 300 | const uint32_t digit = (uint32_t) (uint8_t) (*pos++) - '0'; |
| 301 | if (digit >= 10) { |
| 302 | /* Not really a digit */ |
| 303 | return start; |
| 304 | } |
| 305 | model = model * 10 + digit; |
| 306 | } |
| 307 | |
| 308 | /* Return parsed chipset */ |
| 309 | *chipset = (struct cpuinfo_arm_chipset) { |
| 310 | .vendor = cpuinfo_arm_chipset_vendor_samsung, |
| 311 | .series = cpuinfo_arm_chipset_series_samsung_exynos, |
| 312 | .model = model, |
| 313 | }; |
| 314 | return pos; |
| 315 | } |
| 316 | |
| 317 | /** |
| 318 | * Tries to match /exynos\d{4}$/ signature for Samsung Exynos chipsets. |
| 319 | * If match successful, extracts model information into \p chipset argument. |
| 320 | * |
| 321 | * @param start - start of the platform identifier (ro.board.platform or ro.chipname) to match. |
| 322 | * @param end - end of the platform identifier (ro.board.platform or ro.chipname) to match. |
| 323 | * @param[out] chipset - location where chipset information will be stored upon a successful match. |
| 324 | * |
| 325 | * @returns true if signature matched, false otherwise. |
| 326 | */ |
| 327 | static bool match_exynos( |
| 328 | const char* start, const char* end, |
| 329 | struct cpuinfo_arm_chipset chipset[restrict static 1]) |
| 330 | { |
| 331 | /* Expect exactly 10 symbols: "exynos" (6 symbols) + 4-digit model number */ |
| 332 | if (start + 10 != end) { |
| 333 | return false; |
| 334 | } |
| 335 | |
| 336 | /* Load first 4 bytes as little endian 32-bit word */ |
| 337 | const uint32_t expected_exyn = load_u32le(start); |
| 338 | if (expected_exyn != UINT32_C(0x6E797865) /* "nyxe" = reverse("exyn") */ ) { |
| 339 | return false; |
| 340 | } |
| 341 | |
| 342 | /* Load next 2 bytes as little endian 16-bit word */ |
| 343 | const uint16_t expected_os = load_u16le(start + 4); |
| 344 | if (expected_os != UINT16_C(0x736F) /* "so" = reverse("os") */ ) { |
| 345 | return false; |
| 346 | } |
| 347 | |
| 348 | /* Check and parse 4-digit model number */ |
| 349 | uint32_t model = 0; |
| 350 | for (uint32_t i = 6; i < 10; i++) { |
| 351 | const uint32_t digit = (uint32_t) (uint8_t) start[i] - '0'; |
| 352 | if (digit >= 10) { |
| 353 | /* Not really a digit */ |
| 354 | return false; |
| 355 | } |
| 356 | model = model * 10 + digit; |
| 357 | } |
| 358 | |
| 359 | /* Return parsed chipset. */ |
| 360 | *chipset = (struct cpuinfo_arm_chipset) { |
| 361 | .vendor = cpuinfo_arm_chipset_vendor_samsung, |
| 362 | .series = cpuinfo_arm_chipset_series_samsung_exynos, |
| 363 | .model = model, |
| 364 | }; |
| 365 | return true; |
| 366 | } |
| 367 | |
| 368 | /** |
| 369 | * Tries to match /universal\d{4}$/ signature for Samsung Exynos chipsets. |
| 370 | * If match successful, extracts model information into \p chipset argument. |
| 371 | * |
| 372 | * @param start - start of the platform identifier (/proc/cpuinfo Hardware string, ro.product.board or ro.chipname) |
| 373 | * to match. |
| 374 | * @param end - end of the platform identifier (/proc/cpuinfo Hardware string, ro.product.board or ro.chipname) |
| 375 | * to match. |
| 376 | * @param[out] chipset - location where chipset information will be stored upon a successful match. |
| 377 | * |
| 378 | * @returns true if signature matched, false otherwise. |
| 379 | */ |
| 380 | static bool match_universal( |
| 381 | const char* start, const char* end, |
| 382 | struct cpuinfo_arm_chipset chipset[restrict static 1]) |
| 383 | { |
| 384 | /* Expect exactly 13 symbols: "universal" (9 symbols) + 4-digit model number */ |
| 385 | if (start + 13 != end) { |
| 386 | return false; |
| 387 | } |
| 388 | |
| 389 | /* |
| 390 | * Check that the string starts with "universal". |
| 391 | * Blocks of 4 characters are loaded and compared as little-endian 32-bit word. |
| 392 | * Case-insensitive characters are binary ORed with 0x20 to convert them to lowercase. |
| 393 | */ |
| 394 | const uint8_t expected_u = UINT8_C(0x20) | (uint8_t) start[0]; |
| 395 | if (expected_u != UINT8_C(0x75) /* "u" */) { |
| 396 | return false; |
| 397 | } |
| 398 | const uint32_t expected_nive = UINT32_C(0x20202020) | load_u32le(start + 1); |
| 399 | if (expected_nive != UINT32_C(0x6576696E) /* "evin" = reverse("nive") */ ) { |
| 400 | return false; |
| 401 | } |
| 402 | const uint32_t expected_ersa = UINT32_C(0x20202020) | load_u32le(start + 5); |
| 403 | if (expected_ersa != UINT32_C(0x6C617372) /* "lasr" = reverse("rsal") */) { |
| 404 | return false; |
| 405 | } |
| 406 | |
| 407 | /* Validate and parse 4-digit model number */ |
| 408 | uint32_t model = 0; |
| 409 | for (uint32_t i = 9; i < 13; i++) { |
| 410 | const uint32_t digit = (uint32_t) (uint8_t) start[i] - '0'; |
| 411 | if (digit >= 10) { |
| 412 | /* Not really a digit */ |
| 413 | return false; |
| 414 | } |
| 415 | model = model * 10 + digit; |
| 416 | } |
| 417 | |
| 418 | /* Return parsed chipset. */ |
| 419 | *chipset = (struct cpuinfo_arm_chipset) { |
| 420 | .vendor = cpuinfo_arm_chipset_vendor_samsung, |
| 421 | .series = cpuinfo_arm_chipset_series_samsung_exynos, |
| 422 | .model = model, |
| 423 | }; |
| 424 | return true; |
| 425 | } |
| 426 | |
| 427 | /** |
| 428 | * Compares, case insensitively, a string to known values "SMDK4210" and "SMDK4x12" for Samsung Exynos chipsets. |
| 429 | * If platform identifier matches one of the SMDK* values, extracts model information into \p chipset argument. |
| 430 | * For "SMDK4x12" match, decodes the chipset name using number of cores. |
| 431 | * |
| 432 | * @param start - start of the platform identifier (/proc/cpuinfo Hardware string or ro.product.board) to match. |
| 433 | * @param end - end of the platform identifier (/proc/cpuinfo Hardware string or ro.product.board) to match. |
| 434 | * @param cores - number of cores in the chipset. |
| 435 | * @param[out] chipset - location where chipset information will be stored upon a successful match. |
| 436 | * |
| 437 | * @returns true if signature matched, false otherwise. |
| 438 | */ |
| 439 | static bool match_and_parse_smdk( |
| 440 | const char* start, const char* end, uint32_t cores, |
| 441 | struct cpuinfo_arm_chipset chipset[restrict static 1]) |
| 442 | { |
| 443 | /* Expect exactly 8 symbols: "SMDK" (4 symbols) + 4-digit model number */ |
| 444 | if (start + 8 != end) { |
| 445 | return false; |
| 446 | } |
| 447 | |
| 448 | /* |
| 449 | * Check that string starts with "MT" (case-insensitive). |
| 450 | * The first four characters are loaded as a 32-bit little endian word and converted to lowercase. |
| 451 | */ |
| 452 | const uint32_t expected_smdk = UINT32_C(0x20202020) | load_u32le(start); |
| 453 | if (expected_smdk != UINT32_C(0x6B646D73) /* "kdms" = reverse("smdk") */) { |
| 454 | return false; |
| 455 | } |
| 456 | |
| 457 | /* |
| 458 | * Check that string ends with "4210" or "4x12". |
| 459 | * The last four characters are loaded and compared as a 32-bit little endian word. |
| 460 | */ |
| 461 | uint32_t model = 0; |
| 462 | const uint32_t expected_model = load_u32le(start + 4); |
| 463 | switch (expected_model) { |
| 464 | case UINT32_C(0x30313234): /* "0124" = reverse("4210") */ |
| 465 | model = 4210; |
| 466 | break; |
| 467 | case UINT32_C(0x32317834): /* "21x4" = reverse("4x12") */ |
| 468 | switch (cores) { |
| 469 | case 2: |
| 470 | model = 4212; |
| 471 | break; |
| 472 | case 4: |
| 473 | model = 4412; |
| 474 | break; |
| 475 | default: |
| 476 | cpuinfo_log_warning("system reported invalid %"PRIu32"-core Exynos 4x12 chipset", cores); |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | if (model == 0) { |
| 481 | return false; |
| 482 | } |
| 483 | |
| 484 | *chipset = (struct cpuinfo_arm_chipset) { |
| 485 | .vendor = cpuinfo_arm_chipset_vendor_samsung, |
| 486 | .series = cpuinfo_arm_chipset_series_samsung_exynos, |
| 487 | .model = model, |
| 488 | }; |
| 489 | return true; |
| 490 | } |
| 491 | |
| 492 | /** |
| 493 | * Tries to match /MTK?\d{4}[A-Z]*$/ signature for MediaTek MT chipsets. |
| 494 | * If match successful, extracts model information into \p chipset argument. |
| 495 | * |
| 496 | * @param start - start of the platform identifier (/proc/cpuinfo Hardware string, ro.product.board, ro.board.platform, |
| 497 | * ro.mediatek.platform, or ro.chipname) to match. |
| 498 | * @param end - end of the platform identifier (/proc/cpuinfo Hardware string, ro.product.board, ro.board.platform, |
| 499 | * ro.mediatek.platform, or ro.chipname) to match. |
| 500 | * @param match_end - indicates if the function should attempt to match through the end of the string and fail if there |
| 501 | * are unparsed characters in the end, or match only MTK signature, model number, and some of the |
| 502 | * suffix characters (the ones that pass validation). |
| 503 | * @param[out] chipset - location where chipset information will be stored upon a successful match. |
| 504 | * |
| 505 | * @returns true if signature matched, false otherwise. |
| 506 | */ |
| 507 | static bool match_mt( |
| 508 | const char* start, const char* end, bool match_end, |
| 509 | struct cpuinfo_arm_chipset chipset[restrict static 1]) |
| 510 | { |
| 511 | /* Expect at least 6 symbols: "MT" (2 symbols) + 4-digit model number */ |
| 512 | if (start + 6 > end) { |
| 513 | return false; |
| 514 | } |
| 515 | |
| 516 | /* |
| 517 | * Check that string starts with "MT" (case-insensitive). |
| 518 | * The first two characters are loaded as 16-bit little endian word and converted to lowercase. |
| 519 | */ |
| 520 | const uint16_t mt = UINT16_C(0x2020) | load_u16le(start); |
| 521 | if (mt != UINT16_C(0x746D) /* "tm" */) { |
| 522 | return false; |
| 523 | } |
| 524 | |
| 525 | |
| 526 | /* Some images report "MTK" rather than "MT" */ |
| 527 | const char* pos = start + 2; |
| 528 | if (((uint8_t) *pos | UINT8_C(0x20)) == (uint8_t) 'k') { |
| 529 | pos++; |
| 530 | |
| 531 | /* Expect 4 more symbols after "MTK" (4-digit model number) */ |
| 532 | if (pos + 4 > end) { |
| 533 | return false; |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | /* Validate and parse 4-digit model number */ |
| 538 | uint32_t model = 0; |
| 539 | for (uint32_t i = 0; i < 4; i++) { |
| 540 | const uint32_t digit = (uint32_t) (uint8_t) (*pos++) - '0'; |
| 541 | if (digit >= 10) { |
| 542 | /* Not really a digit */ |
| 543 | return false; |
| 544 | } |
| 545 | model = model * 10 + digit; |
| 546 | } |
| 547 | |
| 548 | /* Record parsed chipset. This implicitly zeroes-out suffix, which will be parsed later. */ |
| 549 | *chipset = (struct cpuinfo_arm_chipset) { |
| 550 | .vendor = cpuinfo_arm_chipset_vendor_mediatek, |
| 551 | .series = cpuinfo_arm_chipset_series_mediatek_mt, |
| 552 | .model = model, |
| 553 | }; |
| 554 | |
| 555 | if (match_end) { |
| 556 | /* Check that the potential suffix does not exceed maximum length */ |
| 557 | const size_t suffix_length = end - pos; |
| 558 | if (suffix_length > CPUINFO_ARM_CHIPSET_SUFFIX_MAX) { |
| 559 | return false; |
| 560 | } |
| 561 | |
| 562 | /* Validate suffix characters and copy them to chipset structure */ |
| 563 | for (size_t i = 0; i < suffix_length; i++) { |
| 564 | const char c = (*pos++); |
| 565 | if (is_ascii_alphabetic(c)) { |
| 566 | /* Matched a letter [A-Za-z], convert to uppercase */ |
| 567 | chipset->suffix[i] = c & '\xDF'; |
| 568 | } else if (c == '/') { |
| 569 | /* Matched a slash '/' */ |
| 570 | chipset->suffix[i] = c; |
| 571 | } else { |
| 572 | /* Invalid suffix character (neither of [A-Za-z/]) */ |
| 573 | return false; |
| 574 | } |
| 575 | } |
| 576 | } else { |
| 577 | /* Validate and parse as many suffix characters as we can */ |
| 578 | for (size_t i = 0; i < CPUINFO_ARM_CHIPSET_SUFFIX_MAX; i++) { |
| 579 | if (pos + i == end) { |
| 580 | break; |
| 581 | } |
| 582 | |
| 583 | const char c = pos[i]; |
| 584 | if (is_ascii_alphabetic(c)) { |
| 585 | /* Matched a letter [A-Za-z], convert to uppercase */ |
| 586 | chipset->suffix[i] = c & '\xDF'; |
| 587 | } else if (c == '/') { |
| 588 | /* Matched a slash '/' */ |
| 589 | chipset->suffix[i] = c; |
| 590 | } else { |
| 591 | /* Invalid suffix character (neither of [A-Za-z/]). This marks the end of the suffix. */ |
| 592 | break; |
| 593 | } |
| 594 | } |
| 595 | } |
| 596 | /* All suffix characters successfully validated and copied to chipset data */ |
| 597 | return true; |
| 598 | } |
| 599 | |
| 600 | /** |
| 601 | * Tries to match /Kirin\s?\d{3}$/ signature for HiSilicon Kirin chipsets. |
| 602 | * If match successful, extracts model information into \p chipset argument. |
| 603 | * |
| 604 | * @param start - start of the /proc/cpuinfo Hardware string to match. |
| 605 | * @param end - end of the /proc/cpuinfo Hardware string to match. |
| 606 | * @param[out] chipset - location where chipset information will be stored upon a successful match. |
| 607 | * |
| 608 | * @returns true if signature matched, false otherwise. |
| 609 | */ |
| 610 | static bool match_kirin( |
| 611 | const char* start, const char* end, |
| 612 | struct cpuinfo_arm_chipset chipset[restrict static 1]) |
| 613 | { |
| 614 | /* Expect 8-9 symbols: "Kirin" (5 symbols) + optional whitespace (1 symbol) + 3-digit model number */ |
| 615 | const size_t length = end - start; |
| 616 | switch (length) { |
| 617 | case 8: |
| 618 | case 9: |
| 619 | break; |
| 620 | default: |
| 621 | return false; |
| 622 | } |
| 623 | |
| 624 | /* Check that the string starts with "Kirin". Symbols 1-5 are loaded and compared as little-endian 32-bit word. */ |
| 625 | if (start[0] != 'K') { |
| 626 | return false; |
| 627 | } |
| 628 | const uint32_t irin = load_u32le(start + 1); |
| 629 | if (irin != UINT32_C(0x6E697269) /* "niri" = reverse("irin") */) { |
| 630 | return false; |
| 631 | } |
| 632 | |
| 633 | /* Check for optional whitespace after "Kirin" */ |
| 634 | if (is_ascii_whitespace(start[5])) { |
| 635 | /* When whitespace is present after "Kirin", expect 9 symbols total */ |
| 636 | if (length != 9) { |
| 637 | return false; |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | /* Validate and parse 3-digit model number */ |
| 642 | uint32_t model = 0; |
| 643 | for (int32_t i = 0; i < 3; i++) { |
| 644 | const uint32_t digit = (uint32_t) (uint8_t) end[i - 3] - '0'; |
| 645 | if (digit >= 10) { |
| 646 | /* Not really a digit */ |
| 647 | return start; |
| 648 | } |
| 649 | model = model * 10 + digit; |
| 650 | } |
| 651 | |
| 652 | /* |
| 653 | * Thats it, return parsed chipset. |
| 654 | * Technically, Kirin 910T has a suffix, but it never appears in the form of "910T" string. |
| 655 | * Instead, Kirin 910T devices report "hi6620oem" string (handled outside of this function). |
| 656 | */ |
| 657 | *chipset = (struct cpuinfo_arm_chipset) { |
| 658 | .vendor = cpuinfo_arm_chipset_vendor_hisilicon, |
| 659 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 660 | .model = model, |
| 661 | }; |
| 662 | return true; |
| 663 | } |
| 664 | |
| 665 | /** |
| 666 | * Tries to match /rk\d{4}[a-z]?$/ signature for Rockchip RK chipsets. |
| 667 | * If match successful, extracts model information into \p chipset argument. |
| 668 | * |
| 669 | * @param start - start of the platform identifier (/proc/cpuinfo Hardware string or ro.board.platform) to match. |
| 670 | * @param end - end of the platform identifier (/proc/cpuinfo Hardware string or ro.board.platform) to match. |
| 671 | * @param[out] chipset - location where chipset information will be stored upon a successful match. |
| 672 | * |
| 673 | * @returns true if signature matched, false otherwise. |
| 674 | */ |
| 675 | static bool match_rk( |
| 676 | const char* start, const char* end, |
| 677 | struct cpuinfo_arm_chipset chipset[restrict static 1]) |
| 678 | { |
| 679 | /* Expect 6-7 symbols: "RK" (2 symbols) + 4-digit model number + optional 1-letter suffix */ |
| 680 | const size_t length = end - start; |
| 681 | switch (length) { |
| 682 | case 6: |
| 683 | case 7: |
| 684 | break; |
| 685 | default: |
| 686 | return false; |
| 687 | } |
| 688 | |
| 689 | /* |
| 690 | * Check that string starts with "RK" (case-insensitive). |
| 691 | * The first two characters are loaded as 16-bit little endian word and converted to lowercase. |
| 692 | */ |
| 693 | const uint16_t expected_rk = UINT16_C(0x2020) | load_u16le(start); |
| 694 | if (expected_rk != UINT16_C(0x6B72) /* "kr" = reverse("rk") */) { |
| 695 | return false; |
| 696 | } |
| 697 | |
| 698 | /* Validate and parse 4-digit model number */ |
| 699 | uint32_t model = 0; |
| 700 | for (uint32_t i = 2; i < 6; i++) { |
| 701 | const uint32_t digit = (uint32_t) (uint8_t) start[i] - '0'; |
| 702 | if (digit >= 10) { |
| 703 | /* Not really a digit */ |
| 704 | return start; |
| 705 | } |
| 706 | model = model * 10 + digit; |
| 707 | } |
| 708 | |
| 709 | /* Parse optional suffix */ |
| 710 | char suffix = 0; |
| 711 | if (length == 7) { |
| 712 | /* Parse the suffix letter */ |
| 713 | const char c = start[6]; |
| 714 | if (is_ascii_alphabetic(c)) { |
| 715 | /* Convert to upper case */ |
| 716 | suffix = c & '\xDF'; |
| 717 | } else { |
| 718 | /* Invalid suffix character */ |
| 719 | return false; |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | /* Return parsed chipset */ |
| 724 | *chipset = (struct cpuinfo_arm_chipset) { |
| 725 | .vendor = cpuinfo_arm_chipset_vendor_rockchip, |
| 726 | .series = cpuinfo_arm_chipset_series_rockchip_rk, |
| 727 | .model = model, |
| 728 | .suffix = { |
| 729 | [0] = suffix, |
| 730 | }, |
| 731 | }; |
| 732 | return true; |
| 733 | } |
| 734 | |
| 735 | /** |
| 736 | * Tries to match, case-insentitively, /sc\d{4}[a-z]*|scx15$/ signature for Spreadtrum SC chipsets. |
| 737 | * If match successful, extracts model information into \p chipset argument. |
| 738 | * |
| 739 | * @param start - start of the platform identifier (/proc/cpuinfo Hardware string, ro.product.board, |
| 740 | * ro.board.platform, or ro.chipname) to match. |
| 741 | * @param end - end of the platform identifier (/proc/cpuinfo Hardware string, ro.product.board, |
| 742 | * ro.board.platform, or ro.chipname) to match. |
| 743 | * @param[out] chipset - location where chipset information will be stored upon a successful match. |
| 744 | * |
| 745 | * @returns true if signature matched, false otherwise. |
| 746 | */ |
| 747 | static bool match_sc( |
| 748 | const char* start, const char* end, |
| 749 | struct cpuinfo_arm_chipset chipset[restrict static 1]) |
| 750 | { |
| 751 | /* Expect at least 5 symbols: "scx15" */ |
| 752 | if (start + 5 > end) { |
| 753 | return false; |
| 754 | } |
| 755 | |
| 756 | /* |
| 757 | * Check that string starts with "SC" (case-insensitive). |
| 758 | * The first two characters are loaded as 16-bit little endian word and converted to lowercase. |
| 759 | */ |
| 760 | const uint16_t expected_sc = UINT16_C(0x2020) | load_u16le(start); |
| 761 | if (expected_sc != UINT16_C(0x6373) /* "cs" = reverse("sc") */) { |
| 762 | return false; |
| 763 | } |
| 764 | |
| 765 | /* Special case: "scx" prefix (SC7715 reported as "scx15") */ |
| 766 | if ((start[2] | '\x20') == 'x') { |
| 767 | /* Expect exactly 5 characters: "scx15" */ |
| 768 | if (start + 5 != end) { |
| 769 | return false; |
| 770 | } |
| 771 | |
| 772 | /* Check that string ends with "15" */ |
| 773 | const uint16_t expected_15 = load_u16le(start + 3); |
| 774 | if (expected_15 != UINT16_C(0x3531) /* "51" = reverse("15") */ ) { |
| 775 | return false; |
| 776 | } |
| 777 | |
| 778 | *chipset = (struct cpuinfo_arm_chipset) { |
| 779 | .vendor = cpuinfo_arm_chipset_vendor_spreadtrum, |
| 780 | .series = cpuinfo_arm_chipset_series_spreadtrum_sc, |
| 781 | .model = 7715, |
| 782 | }; |
| 783 | return true; |
| 784 | } |
| 785 | |
| 786 | /* Expect at least 6 symbols: "SC" (2 symbols) + 4-digit model number */ |
| 787 | if (start + 6 > end) { |
| 788 | return false; |
| 789 | } |
| 790 | |
| 791 | /* Validate and parse 4-digit model number */ |
| 792 | uint32_t model = 0; |
| 793 | for (uint32_t i = 2; i < 6; i++) { |
| 794 | const uint32_t digit = (uint32_t) (uint8_t) start[i] - '0'; |
| 795 | if (digit >= 10) { |
| 796 | /* Not really a digit */ |
| 797 | return false; |
| 798 | } |
| 799 | model = model * 10 + digit; |
| 800 | } |
| 801 | |
| 802 | /* Write parsed chipset */ |
| 803 | *chipset = (struct cpuinfo_arm_chipset) { |
| 804 | .vendor = cpuinfo_arm_chipset_vendor_spreadtrum, |
| 805 | .series = cpuinfo_arm_chipset_series_spreadtrum_sc, |
| 806 | .model = model, |
| 807 | }; |
| 808 | |
| 809 | /* Validate and copy suffix letters. If suffix is too long, truncate at CPUINFO_ARM_CHIPSET_SUFFIX_MAX letters. */ |
| 810 | const char* suffix = start + 6; |
| 811 | for (size_t i = 0; i < CPUINFO_ARM_CHIPSET_SUFFIX_MAX; i++) { |
| 812 | if (suffix + i == end) { |
| 813 | break; |
| 814 | } |
| 815 | |
| 816 | const char c = suffix[i]; |
| 817 | if (!is_ascii_alphabetic(c)) { |
| 818 | /* Invalid suffix character */ |
| 819 | return false; |
| 820 | } |
| 821 | /* Convert suffix letter to uppercase */ |
| 822 | chipset->suffix[i] = c & '\xDF'; |
| 823 | } |
| 824 | return true; |
| 825 | } |
| 826 | |
| 827 | /** |
| 828 | * Tries to match /lc\d{4}[a-z]?$/ signature for Leadcore LC chipsets. |
| 829 | * If match successful, extracts model information into \p chipset argument. |
| 830 | * |
| 831 | * @param start - start of the platform identifier (ro.product.board or ro.board.platform) to match. |
| 832 | * @param end - end of the platform identifier (ro.product.board or ro.board.platform) to match. |
| 833 | * @param[out] chipset - location where chipset information will be stored upon a successful match. |
| 834 | * |
| 835 | * @returns true if signature matched, false otherwise. |
| 836 | */ |
| 837 | static bool match_lc( |
| 838 | const char* start, const char* end, |
| 839 | struct cpuinfo_arm_chipset chipset[restrict static 1]) |
| 840 | { |
| 841 | /* Expect at 6-7 symbols: "lc" (2 symbols) + 4-digit model number + optional 1-letter suffix */ |
| 842 | const size_t length = end - start; |
| 843 | switch (length) { |
| 844 | case 6: |
| 845 | case 7: |
| 846 | break; |
| 847 | default: |
| 848 | return false; |
| 849 | } |
| 850 | |
| 851 | /* Check that string starts with "lc". The first two characters are loaded as 16-bit little endian word */ |
| 852 | const uint16_t expected_lc = load_u16le(start); |
| 853 | if (expected_lc != UINT16_C(0x636C) /* "cl" = reverse("lc") */) { |
| 854 | return false; |
| 855 | } |
| 856 | |
| 857 | /* Validate and parse 4-digit model number */ |
| 858 | uint32_t model = 0; |
| 859 | for (uint32_t i = 2; i < 6; i++) { |
| 860 | const uint32_t digit = (uint32_t) (uint8_t) start[i] - '0'; |
| 861 | if (digit >= 10) { |
| 862 | /* Not really a digit */ |
| 863 | return false; |
| 864 | } |
| 865 | model = model * 10 + digit; |
| 866 | } |
| 867 | |
| 868 | /* Parse optional suffix letter */ |
| 869 | char suffix = 0; |
| 870 | if (length == 7) { |
| 871 | const char c = start[6]; |
| 872 | if (is_ascii_alphabetic(c)) { |
| 873 | /* Convert to uppercase */ |
| 874 | chipset->suffix[0] = c & '\xDF'; |
| 875 | } else { |
| 876 | /* Invalid suffix character */ |
| 877 | return false; |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | /* Return parsed chipset */ |
| 882 | *chipset = (struct cpuinfo_arm_chipset) { |
| 883 | .vendor = cpuinfo_arm_chipset_vendor_leadcore, |
| 884 | .series = cpuinfo_arm_chipset_series_leadcore_lc, |
| 885 | .model = model, |
| 886 | .suffix = { |
| 887 | [0] = suffix, |
| 888 | }, |
| 889 | }; |
| 890 | return true; |
| 891 | } |
| 892 | |
| 893 | /** |
| 894 | * Tries to match /PXA(\d{3,4}|1L88)$/ signature for Marvell PXA chipsets. |
| 895 | * If match successful, extracts model information into \p chipset argument. |
| 896 | * |
| 897 | * @param start - start of the platform identifier (/proc/cpuinfo Hardware string, ro.product.board or ro.chipname) |
| 898 | * to match. |
| 899 | * @param end - end of the platform identifier (/proc/cpuinfo Hardaware string, ro.product.board or ro.chipname) to |
| 900 | * match. |
| 901 | * @param[out] chipset - location where chipset information will be stored upon a successful match. |
| 902 | * |
| 903 | * @returns true if signature matched, false otherwise. |
| 904 | */ |
| 905 | static bool match_pxa( |
| 906 | const char* start, const char* end, |
| 907 | struct cpuinfo_arm_chipset chipset[restrict static 1]) |
| 908 | { |
| 909 | /* Expect 6-7 symbols: "PXA" (3 symbols) + 3-4 digit model number */ |
| 910 | const size_t length = end - start; |
| 911 | switch (length) { |
| 912 | case 6: |
| 913 | case 7: |
| 914 | break; |
| 915 | default: |
| 916 | return false; |
| 917 | } |
| 918 | |
| 919 | /* Check that the string starts with "PXA". Symbols 1-3 are loaded and compared as little-endian 16-bit word. */ |
| 920 | if (start[0] != 'P') { |
| 921 | return false; |
| 922 | } |
| 923 | const uint16_t expected_xa = load_u16le(start + 1); |
| 924 | if (expected_xa != UINT16_C(0x4158) /* "AX" = reverse("XA") */) { |
| 925 | return false; |
| 926 | } |
| 927 | |
| 928 | uint32_t model = 0; |
| 929 | |
| 930 | |
| 931 | /* Check for a very common typo: "PXA1L88" for "PXA1088" */ |
| 932 | if (length == 7) { |
| 933 | /* Load 4 model "number" symbols as a little endian 32-bit word and compare to "1L88" */ |
| 934 | const uint32_t expected_1L88 = load_u32le(start + 3); |
| 935 | if (expected_1L88 == UINT32_C(0x38384C31) /* "88L1" = reverse("1L88") */) { |
| 936 | model = 1088; |
| 937 | goto write_chipset; |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | /* Check and parse 3-4 digit model number */ |
| 942 | for (uint32_t i = 3; i < length; i++) { |
| 943 | const uint32_t digit = (uint32_t) (uint8_t) start[i] - '0'; |
| 944 | if (digit >= 10) { |
| 945 | /* Not really a digit */ |
| 946 | return false; |
| 947 | } |
| 948 | model = model * 10 + digit; |
| 949 | } |
| 950 | |
| 951 | /* Return parsed chipset. */ |
| 952 | write_chipset: |
| 953 | *chipset = (struct cpuinfo_arm_chipset) { |
| 954 | .vendor = cpuinfo_arm_chipset_vendor_marvell, |
| 955 | .series = cpuinfo_arm_chipset_series_marvell_pxa, |
| 956 | .model = model, |
| 957 | }; |
| 958 | return true; |
| 959 | } |
| 960 | |
| 961 | /** |
| 962 | * Tries to match /OMAP\d{4}$/ signature for Texas Instruments OMAP chipsets. |
| 963 | * If match successful, extracts model information into \p chipset argument. |
| 964 | * |
| 965 | * @param start - start of the /proc/cpuinfo Hardware string to match. |
| 966 | * @param end - end of the /proc/cpuinfo Hardaware string to match. |
| 967 | * @param[out] chipset - location where chipset information will be stored upon a successful match. |
| 968 | * |
| 969 | * @returns true if signature matched, false otherwise. |
| 970 | */ |
| 971 | static bool match_omap( |
| 972 | const char* start, const char* end, |
| 973 | struct cpuinfo_arm_chipset chipset[restrict static 1]) |
| 974 | { |
| 975 | /* Expect exactly 8 symbols: "OMAP" (4 symbols) + 4-digit model number */ |
| 976 | if (start + 8 != end) { |
| 977 | return false; |
| 978 | } |
| 979 | |
| 980 | /* Check that the string starts with "OMAP". Symbols 0-4 are loaded and compared as little-endian 32-bit word. */ |
| 981 | const uint32_t expected_omap = load_u32le(start); |
| 982 | if (expected_omap != UINT32_C(0x50414D4F) /* "PAMO" = reverse("OMAP") */) { |
| 983 | return false; |
| 984 | } |
| 985 | |
| 986 | /* Validate and parse 4-digit model number */ |
| 987 | uint32_t model = 0; |
| 988 | for (uint32_t i = 4; i < 8; i++) { |
| 989 | const uint32_t digit = (uint32_t) (uint8_t) start[i] - '0'; |
| 990 | if (digit >= 10) { |
| 991 | /* Not really a digit */ |
| 992 | return false; |
| 993 | } |
| 994 | model = model * 10 + digit; |
| 995 | } |
| 996 | |
| 997 | /* Return parsed chipset. */ |
| 998 | *chipset = (struct cpuinfo_arm_chipset) { |
| 999 | .vendor = cpuinfo_arm_chipset_vendor_texas_instruments, |
| 1000 | .series = cpuinfo_arm_chipset_series_texas_instruments_omap, |
| 1001 | .model = model, |
| 1002 | }; |
| 1003 | return true; |
| 1004 | } |
| 1005 | |
| 1006 | /** |
| 1007 | * Compares platform identifier string to known values for Broadcom chipsets. |
| 1008 | * If the string matches one of the known values, the function decodes Broadcom chipset from frequency and number of |
| 1009 | * cores into \p chipset argument. |
| 1010 | * |
| 1011 | * @param start - start of the platform identifier (ro.product.board or ro.board.platform) to match. |
| 1012 | * @param end - end of the platform identifier (ro.product.board or ro.board.platform) to match. |
| 1013 | * @param cores - number of cores in the chipset. |
| 1014 | * @param max_cpu_freq_max - maximum of /sys/devices/system/cpu/cpu<number>/cpofreq/cpu_freq_max values. |
| 1015 | * @param[out] chipset - location where chipset information will be stored upon a successful match and decoding. |
| 1016 | * |
| 1017 | * @returns true if signature matched (even if exact model can't be decoded), false otherwise. |
| 1018 | */ |
| 1019 | static bool match_and_parse_broadcom( |
| 1020 | const char* start, const char* end, uint32_t cores, uint32_t max_cpu_freq_max, |
| 1021 | struct cpuinfo_arm_chipset chipset[restrict static 1]) |
| 1022 | { |
| 1023 | /* Expect 4-6 symbols: "java" (4 symbols), "rhea" (4 symbols), "capri" (5 symbols), or "hawaii" (6 symbols) */ |
| 1024 | const size_t length = end - start; |
| 1025 | switch (length) { |
| 1026 | case 4: |
| 1027 | case 5: |
| 1028 | case 6: |
| 1029 | break; |
| 1030 | default: |
| 1031 | return false; |
| 1032 | } |
| 1033 | |
| 1034 | /* |
| 1035 | * Compare the platform identifier to known values for Broadcom chipsets: |
| 1036 | * - "rhea" |
| 1037 | * - "java" |
| 1038 | * - "capri" |
| 1039 | * - "hawaii" |
| 1040 | * Upon a successful match, decode chipset name from frequency and number of cores. |
| 1041 | */ |
| 1042 | uint32_t model = 0; |
| 1043 | char suffix = 0; |
| 1044 | const uint32_t expected_platform = load_u32le(start); |
| 1045 | switch (expected_platform) { |
| 1046 | case UINT32_C(0x61656872): /* "aehr" = reverse("rhea") */ |
| 1047 | if (length == 4) { |
| 1048 | /* |
| 1049 | * Detected "rhea" platform: |
| 1050 | * - 1 core @ 849999 KHz -> BCM21654 |
| 1051 | * - 1 core @ 999999 KHz -> BCM21654G |
| 1052 | */ |
| 1053 | if (cores == 1) { |
| 1054 | model = 21654; |
| 1055 | if (max_cpu_freq_max >= 999999) { |
| 1056 | suffix = 'G'; |
| 1057 | } |
| 1058 | } |
| 1059 | } |
| 1060 | break; |
| 1061 | case UINT32_C(0x6176616A): /* "avaj" = reverse("java") */ |
| 1062 | if (length == 4) { |
| 1063 | /* |
| 1064 | * Detected "java" platform: |
| 1065 | * - 4 cores -> BCM23550 |
| 1066 | */ |
| 1067 | if (cores == 4) { |
| 1068 | model = 23550; |
| 1069 | } |
| 1070 | } |
| 1071 | break; |
| 1072 | case UINT32_C(0x61776168): /* "awah" = reverse("hawa") */ |
| 1073 | if (length == 6) { |
| 1074 | /* Check that string equals "hawaii" */ |
| 1075 | const uint16_t expected_ii = load_u16le(start + 4); |
| 1076 | if (expected_ii == UINT16_C(0x6969) /* "ii" */ ) { |
| 1077 | /* |
| 1078 | * Detected "hawaii" platform: |
| 1079 | * - 1 core -> BCM21663 |
| 1080 | * - 2 cores @ 999999 KHz -> BCM21664 |
| 1081 | * - 2 cores @ 1200000 KHz -> BCM21664T |
| 1082 | */ |
| 1083 | switch (cores) { |
| 1084 | case 1: |
| 1085 | model = 21663; |
| 1086 | break; |
| 1087 | case 2: |
| 1088 | model = 21664; |
| 1089 | if (max_cpu_freq_max >= 1200000) { |
| 1090 | suffix = 'T'; |
| 1091 | } |
| 1092 | break; |
| 1093 | } |
| 1094 | } |
| 1095 | } |
| 1096 | break; |
| 1097 | case UINT32_C(0x72706163): /* "rpac" = reverse("capr") */ |
| 1098 | if (length == 5) { |
| 1099 | /* Check that string equals "capri" */ |
| 1100 | if (start[4] == 'i') { |
| 1101 | /* |
| 1102 | * Detected "capri" platform: |
| 1103 | * - 2 cores -> BCM28155 |
| 1104 | */ |
| 1105 | if (cores == 2) { |
| 1106 | model = 28155; |
| 1107 | } |
| 1108 | } |
| 1109 | } |
| 1110 | break; |
| 1111 | } |
| 1112 | |
| 1113 | if (model != 0) { |
| 1114 | /* Chipset was successfully decoded */ |
| 1115 | *chipset = (struct cpuinfo_arm_chipset) { |
| 1116 | .vendor = cpuinfo_arm_chipset_vendor_broadcom, |
| 1117 | .series = cpuinfo_arm_chipset_series_broadcom_bcm, |
| 1118 | .model = model, |
| 1119 | .suffix = { |
| 1120 | [0] = suffix, |
| 1121 | }, |
| 1122 | }; |
| 1123 | } |
| 1124 | return model != 0; |
| 1125 | } |
| 1126 | |
| 1127 | struct sunxi_map_entry { |
| 1128 | uint8_t sunxi; |
| 1129 | uint8_t cores; |
| 1130 | uint8_t model; |
| 1131 | char suffix; |
| 1132 | }; |
| 1133 | |
| 1134 | static const struct sunxi_map_entry sunxi_map_entries[] = { |
| 1135 | { |
| 1136 | /* ("sun4i", 1) -> "A10" */ |
| 1137 | .sunxi = 4, |
| 1138 | .cores = 1, |
| 1139 | .model = 10, |
| 1140 | }, |
| 1141 | { |
| 1142 | /* ("sun5i", 1) -> "A13" */ |
| 1143 | .sunxi = 5, |
| 1144 | .cores = 1, |
| 1145 | .model = 13, |
| 1146 | }, |
| 1147 | { |
| 1148 | /* ("sun6i", 4) -> "A31" */ |
| 1149 | .sunxi = 6, |
| 1150 | .cores = 4, |
| 1151 | .model = 31, |
| 1152 | }, |
| 1153 | { |
| 1154 | /* ("sun7i", 2) -> "A20" */ |
| 1155 | .sunxi = 7, |
| 1156 | .cores = 2, |
| 1157 | .model = 20, |
| 1158 | |
| 1159 | }, |
| 1160 | { |
| 1161 | /* ("sun8i", 2) -> "A23" */ |
| 1162 | .sunxi = 8, |
| 1163 | .cores = 2, |
| 1164 | .model = 23, |
| 1165 | }, |
| 1166 | { |
| 1167 | /* ("sun8i", 4) -> "A33" */ |
| 1168 | .sunxi = 8, |
| 1169 | .cores = 4, |
| 1170 | .model = 33, |
| 1171 | }, |
| 1172 | { |
| 1173 | /* ("sun8i", 8) -> "A83T" */ |
| 1174 | .sunxi = 8, |
| 1175 | .cores = 8, |
| 1176 | .model = 83, |
| 1177 | .suffix = 'T', |
| 1178 | }, |
| 1179 | { |
| 1180 | /* ("sun9i", 8) -> "A80" */ |
| 1181 | .sunxi = 9, |
| 1182 | .cores = 8, |
| 1183 | .model = 80, |
| 1184 | }, |
| 1185 | { |
| 1186 | /* ("sun50i", 4) -> "A64" */ |
| 1187 | .sunxi = 50, |
| 1188 | .cores = 4, |
| 1189 | .model = 64, |
| 1190 | }, |
| 1191 | }; |
| 1192 | |
| 1193 | /** |
| 1194 | * Tries to match /proc/cpuinfo Hardware string to Allwinner /sun\d+i/ signature. |
| 1195 | * If the string matches signature, the function decodes Allwinner chipset from the number in the signature and the |
| 1196 | * number of cores, and stores it in \p chipset argument. |
| 1197 | * |
| 1198 | * @param start - start of the /proc/cpuinfo Hardware string to match. |
| 1199 | * @param end - end of the /proc/cpuinfo Hardware string to match. |
| 1200 | * @param cores - number of cores in the chipset. |
| 1201 | * @param[out] chipset - location where chipset information will be stored upon a successful match and decoding. |
| 1202 | * |
| 1203 | * @returns true if signature matched (even if exact model can't be decoded), false otherwise. |
| 1204 | */ |
| 1205 | static bool match_and_parse_sunxi( |
| 1206 | const char* start, const char* end, uint32_t cores, |
| 1207 | struct cpuinfo_arm_chipset chipset[restrict static 1]) |
| 1208 | { |
| 1209 | /* Expect at least 5 symbols: "sun" (3 symbols) + platform id (1-2 digits) + "i" (1 symbol) */ |
| 1210 | if (start + 5 > end) { |
| 1211 | return false; |
| 1212 | } |
| 1213 | |
| 1214 | /* Compare the first 3 characters to "sun" */ |
| 1215 | if (start[0] != 's') { |
| 1216 | return false; |
| 1217 | } |
| 1218 | const uint16_t expected_un = load_u16le(start + 1); |
| 1219 | if (expected_un != UINT16_C(0x6E75) /* "nu" = reverse("un") */) { |
| 1220 | return false; |
| 1221 | } |
| 1222 | |
| 1223 | /* Check and parse the first (required) digit of the sunXi platform id */ |
| 1224 | uint32_t sunxi_platform = 0; |
| 1225 | { |
| 1226 | const uint32_t digit = (uint32_t) (uint8_t) start[3] - '0'; |
| 1227 | if (digit >= 10) { |
| 1228 | /* Not really a digit */ |
| 1229 | return false; |
| 1230 | } |
| 1231 | sunxi_platform = digit; |
| 1232 | } |
| 1233 | |
| 1234 | /* Parse optional second digit of the sunXi platform id */ |
| 1235 | const char* pos = start + 4; |
| 1236 | { |
| 1237 | const uint32_t digit = (uint32_t) (uint8_t) (*pos) - '0'; |
| 1238 | if (digit < 10) { |
| 1239 | sunxi_platform = sunxi_platform * 10 + digit; |
| 1240 | if (++pos == end) { |
| 1241 | /* Expected one more character, final 'i' letter */ |
| 1242 | return false; |
| 1243 | } |
| 1244 | } |
| 1245 | } |
| 1246 | |
| 1247 | /* Validate the final 'i' letter */ |
| 1248 | if (*pos != 'i') { |
| 1249 | return false; |
| 1250 | } |
| 1251 | |
| 1252 | /* Compare sunXi platform id and number of cores to tabluted values to decode chipset name */ |
| 1253 | uint32_t model = 0; |
| 1254 | char suffix = 0; |
| 1255 | for (size_t i = 0; i < CPUINFO_COUNT_OF(sunxi_map_entries); i++) { |
| 1256 | if (sunxi_platform == sunxi_map_entries[i].sunxi && cores == sunxi_map_entries[i].cores) { |
| 1257 | model = sunxi_map_entries[i].model; |
| 1258 | suffix = sunxi_map_entries[i].suffix; |
| 1259 | break; |
| 1260 | } |
| 1261 | } |
| 1262 | |
| 1263 | if (model == 0) { |
| 1264 | cpuinfo_log_info("unrecognized %"PRIu32"-core Allwinner sun%"PRIu32" platform", cores, sunxi_platform); |
| 1265 | } |
| 1266 | /* Create chipset name from decoded data */ |
| 1267 | *chipset = (struct cpuinfo_arm_chipset) { |
| 1268 | .vendor = cpuinfo_arm_chipset_vendor_allwinner, |
| 1269 | .series = cpuinfo_arm_chipset_series_allwinner_a, |
| 1270 | .model = model, |
| 1271 | .suffix = { |
| 1272 | [0] = suffix, |
| 1273 | }, |
| 1274 | }; |
| 1275 | return true; |
| 1276 | } |
| 1277 | |
| 1278 | /** |
| 1279 | * Compares /proc/cpuinfo Hardware string to "WMT" signature. |
| 1280 | * If the string matches signature, the function decodes WonderMedia chipset from frequency and number of cores into |
| 1281 | * \p chipset argument. |
| 1282 | * |
| 1283 | * @param start - start of the /proc/cpuinfo Hardware string to match. |
| 1284 | * @param end - end of the /proc/cpuinfo Hardware string to match. |
| 1285 | * @param cores - number of cores in the chipset. |
| 1286 | * @param max_cpu_freq_max - maximum of /sys/devices/system/cpu/cpu<number>/cpofreq/cpu_freq_max values. |
| 1287 | * @param[out] chipset - location where chipset information will be stored upon a successful match and decoding. |
| 1288 | * |
| 1289 | * @returns true if signature matched (even if exact model can't be decoded), false otherwise. |
| 1290 | */ |
| 1291 | static bool match_and_parse_wmt( |
| 1292 | const char* start, const char* end, uint32_t cores, uint32_t max_cpu_freq_max, |
| 1293 | struct cpuinfo_arm_chipset chipset[restrict static 1]) |
| 1294 | { |
| 1295 | /* Expected 3 symbols: "WMT" */ |
| 1296 | if (start + 3 != end) { |
| 1297 | return false; |
| 1298 | } |
| 1299 | |
| 1300 | /* Compare string to "WMT" */ |
| 1301 | if (start[0] != 'W') { |
| 1302 | return false; |
| 1303 | } |
| 1304 | const uint16_t expected_mt = load_u16le(start + 1); |
| 1305 | if (expected_mt != UINT16_C(0x544D) /* "TM" = reverse("MT") */) { |
| 1306 | return false; |
| 1307 | } |
| 1308 | |
| 1309 | /* Decode chipset name from frequency and number of cores */ |
| 1310 | uint32_t model = 0; |
| 1311 | switch (cores) { |
| 1312 | case 1: |
| 1313 | switch (max_cpu_freq_max) { |
| 1314 | case 1008000: |
| 1315 | /* 1 core @ 1008000 KHz -> WM8950 */ |
| 1316 | model = 8950; |
| 1317 | break; |
| 1318 | case 1200000: |
| 1319 | /* 1 core @ 1200000 KHz -> WM8850 */ |
| 1320 | model = 8850; |
| 1321 | break; |
| 1322 | } |
| 1323 | break; |
| 1324 | case 2: |
| 1325 | if (max_cpu_freq_max == 1500000) { |
| 1326 | /* 2 cores @ 1500000 KHz -> WM8880 */ |
| 1327 | model = 8880; |
| 1328 | } |
| 1329 | break; |
| 1330 | } |
| 1331 | |
| 1332 | if (model == 0) { |
| 1333 | cpuinfo_log_info("unrecognized WonderMedia platform with %"PRIu32" cores at %"PRIu32" KHz", |
| 1334 | cores, max_cpu_freq_max); |
| 1335 | } |
| 1336 | *chipset = (struct cpuinfo_arm_chipset) { |
| 1337 | .vendor = cpuinfo_arm_chipset_vendor_wondermedia, |
| 1338 | .series = cpuinfo_arm_chipset_series_wondermedia_wm, |
| 1339 | .model = model, |
| 1340 | }; |
| 1341 | return true; |
| 1342 | } |
| 1343 | |
| 1344 | struct huawei_map_entry { |
| 1345 | uint32_t platform; |
| 1346 | uint32_t model; |
| 1347 | }; |
| 1348 | |
| 1349 | static const struct huawei_map_entry huawei_platform_map[] = { |
| 1350 | { |
| 1351 | /* "BAC" -> Kirin 659 */ |
| 1352 | .platform = UINT32_C(0x00434142), /* "\0CAB" = reverse("BAC\0") */ |
| 1353 | .model = 659, |
| 1354 | }, |
| 1355 | { |
| 1356 | /* "DUK" -> Kirin 960 */ |
| 1357 | .platform = UINT32_C(0x004B5544), /* "\0KUD" = reverse("DUK\0") */ |
| 1358 | .model = 960, |
| 1359 | }, |
| 1360 | { |
| 1361 | /* "EVA" -> Kirin 955 */ |
| 1362 | .platform = UINT32_C(0x00415645), /* "\0AVE" = reverse("EVA\0") */ |
| 1363 | .model = 955, |
| 1364 | }, |
| 1365 | { |
| 1366 | /* "FRD" -> Kirin 950 */ |
| 1367 | .platform = UINT32_C(0x00445246), /* "\0DRF" = reverse("FRD\0") */ |
| 1368 | .model = 950, |
| 1369 | }, |
| 1370 | { |
| 1371 | /* "KNT" -> Kirin 950 */ |
| 1372 | .platform = UINT32_C(0x00544E4B), /* "\0TNK" = reverse("KNT\0") */ |
| 1373 | .model = 950, |
| 1374 | }, |
| 1375 | { |
| 1376 | /* "LON" -> Kirin 960 */ |
| 1377 | .platform = UINT32_C(0x004E4F4C), /* "\0NOL" = reverse("LON\0") */ |
| 1378 | .model = 960, |
| 1379 | }, |
| 1380 | { |
| 1381 | /* "MHA" -> Kirin 960 */ |
| 1382 | .platform = UINT32_C(0x0041484D), /* "\0AHM" = reverse("MHA\0") */ |
| 1383 | .model = 960, |
| 1384 | }, |
| 1385 | { |
| 1386 | /* "NXT" -> Kirin 950 */ |
| 1387 | .platform = UINT32_C(0x0054584E), /* "\0TXN" = reverse("NXT\0") */ |
| 1388 | .model = 950, |
| 1389 | }, |
| 1390 | { |
| 1391 | /* "STF" -> Kirin 960 */ |
| 1392 | .platform = UINT32_C(0x00465453), /* "\0FTS" = reverse("STF\0") */ |
| 1393 | .model = 960, |
| 1394 | }, |
| 1395 | { |
| 1396 | /* "VIE" -> Kirin 955 */ |
| 1397 | .platform = UINT32_C(0x00454956), /* "\0EIV" = reverse("VIE\0") */ |
| 1398 | .model = 955, |
| 1399 | }, |
| 1400 | { |
| 1401 | /* "VKY" -> Kirin 960 */ |
| 1402 | .platform = UINT32_C(0x00594B56), /* "\0YKV" = reverse("VKY\0") */ |
| 1403 | .model = 960, |
| 1404 | }, |
| 1405 | { |
| 1406 | /* "VTR" -> Kirin 960 */ |
| 1407 | .platform = UINT32_C(0x00525456), /* "\0RTV" = reverse("VTR\0") */ |
| 1408 | .model = 960, |
| 1409 | }, |
| 1410 | }; |
| 1411 | |
| 1412 | /** |
| 1413 | * Tries to match ro.product.board string to Huawei /([A-Z]{3})(\-[A-Z]?L\d{2})$/ signature where \1 is one of the |
| 1414 | * known values for Huawei devices, which do not report chipset name elsewhere. |
| 1415 | * If the string matches signature, the function decodes chipset (always HiSilicon Kirin for matched devices) from |
| 1416 | * the number in the signature and stores it in \p chipset argument. |
| 1417 | * |
| 1418 | * @param start - start of the ro.product.board string to match. |
| 1419 | * @param end - end of the ro.product.board string to match. |
| 1420 | * @param[out] chipset - location where chipset information will be stored upon a successful match and decoding. |
| 1421 | * |
| 1422 | * @returns true if signature matched, false otherwise. |
| 1423 | */ |
| 1424 | static bool match_and_parse_huawei( |
| 1425 | const char* start, const char* end, |
| 1426 | struct cpuinfo_arm_chipset chipset[restrict static 1]) |
| 1427 | { |
| 1428 | /* |
| 1429 | * Expect length of either 3, 7 or 8, exactly: |
| 1430 | * - 3-letter platform identifier (see huawei_platform_map) |
| 1431 | * - 3-letter platform identifier + '-' + 'L' + two digits |
| 1432 | * - 3-letter platform identifier + '-' + capital letter + 'L' + two digits |
| 1433 | */ |
| 1434 | const size_t length = end - start; |
| 1435 | switch (length) { |
| 1436 | case 3: |
| 1437 | case 7: |
| 1438 | case 8: |
| 1439 | break; |
| 1440 | default: |
| 1441 | return false; |
| 1442 | } |
| 1443 | |
| 1444 | /* |
| 1445 | * Try to find the first three-letter substring in among the tabulated entries for Huawei devices. |
| 1446 | * The first three letters are loaded and compared as a little-endian 24-bit word. |
| 1447 | */ |
| 1448 | uint32_t model = 0; |
| 1449 | const uint32_t target_platform_id = load_u24le(start); |
| 1450 | for (uint32_t i = 0; i < CPUINFO_COUNT_OF(huawei_platform_map); i++) { |
| 1451 | if (huawei_platform_map[i].platform == target_platform_id) { |
| 1452 | model = huawei_platform_map[i].model; |
| 1453 | break; |
| 1454 | } |
| 1455 | } |
| 1456 | |
| 1457 | if (model == 0) { |
| 1458 | /* Platform does not match the tabulated Huawei entries */ |
| 1459 | return false; |
| 1460 | } |
| 1461 | |
| 1462 | if (length > 3) { |
| 1463 | /* |
| 1464 | * Check that: |
| 1465 | * - The symbol after platform id is a dash |
| 1466 | * - The symbol after it is an uppercase letter. For 7-symbol strings, the symbol is just 'L'. |
| 1467 | */ |
| 1468 | if (start[3] != '-' || !is_ascii_alphabetic_uppercase(start[4])) { |
| 1469 | return false; |
| 1470 | } |
| 1471 | |
| 1472 | /* Check that the last 3 entries are /L\d\d/ */ |
| 1473 | if (end[-3] != 'L' || !is_ascii_numeric(end[-2]) || !is_ascii_numeric(end[-1])) { |
| 1474 | return false; |
| 1475 | } |
| 1476 | } |
| 1477 | |
| 1478 | /* All checks succeeded, commit chipset name */ |
| 1479 | *chipset = (struct cpuinfo_arm_chipset) { |
| 1480 | .vendor = cpuinfo_arm_chipset_vendor_hisilicon, |
| 1481 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 1482 | .model = model, |
| 1483 | }; |
| 1484 | return true; |
| 1485 | } |
| 1486 | |
| 1487 | /** |
| 1488 | * Tries to match /tcc\d{3}x$/ signature for Telechips TCCXXXx chipsets. |
| 1489 | * If match successful, extracts model information into \p chipset argument. |
| 1490 | * |
| 1491 | * @param start - start of the /proc/cpuinfo Hardware string to match. |
| 1492 | * @param end - end of the /proc/cpuinfo Hardware string to match. |
| 1493 | * @param[out] chipset - location where chipset information will be stored upon a successful match. |
| 1494 | * |
| 1495 | * @returns true if signature matched, false otherwise. |
| 1496 | */ |
| 1497 | static bool match_tcc( |
| 1498 | const char* start, const char* end, |
| 1499 | struct cpuinfo_arm_chipset chipset[restrict static 1]) |
| 1500 | { |
| 1501 | /* Expect exactly 7 symbols: "tcc" (3 symbols) + 3-digit model number + fixed "x" suffix */ |
| 1502 | if (start + 7 != end) { |
| 1503 | return false; |
| 1504 | } |
| 1505 | |
| 1506 | /* Quick check for the first character */ |
| 1507 | if (start[0] != 't') { |
| 1508 | return false; |
| 1509 | } |
| 1510 | |
| 1511 | /* Load the next 2 bytes as little endian 16-bit word */ |
| 1512 | const uint16_t expected_cc = load_u16le(start + 1); |
| 1513 | if (expected_cc != UINT16_C(0x6363) /* "cc" */ ) { |
| 1514 | return false; |
| 1515 | } |
| 1516 | |
| 1517 | /* Check and parse 3-digit model number */ |
| 1518 | uint32_t model = 0; |
| 1519 | for (uint32_t i = 3; i < 6; i++) { |
| 1520 | const uint32_t digit = (uint32_t) (uint8_t) start[i] - '0'; |
| 1521 | if (digit >= 10) { |
| 1522 | /* Not really a digit */ |
| 1523 | return false; |
| 1524 | } |
| 1525 | model = model * 10 + digit; |
| 1526 | } |
| 1527 | |
| 1528 | /* Check the fixed 'x' suffix in the end */ |
| 1529 | if (start[6] != 'x') { |
| 1530 | return false; |
| 1531 | } |
| 1532 | |
| 1533 | /* Commit parsed chipset. */ |
| 1534 | *chipset = (struct cpuinfo_arm_chipset) { |
| 1535 | .vendor = cpuinfo_arm_chipset_vendor_telechips, |
| 1536 | .series = cpuinfo_arm_chipset_series_telechips_tcc, |
| 1537 | .model = model, |
Marat Dukhan | 63a6a10 | 2017-08-24 21:28:02 -0700 | [diff] [blame] | 1538 | .suffix = { |
| 1539 | [0] = 'X' |
| 1540 | }, |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1541 | }; |
| 1542 | return true; |
| 1543 | } |
| 1544 | |
| 1545 | /* |
| 1546 | * Compares ro.board.platform string to nVidia Tegra signatures ("tegra" and "tegra3") |
| 1547 | * This check has effect on how /proc/cpuinfo Hardware string is interpreted. |
| 1548 | * |
| 1549 | * @param start - start of the ro.board.platform string to check. |
| 1550 | * @param end - end of the ro.board.platform string to check. |
| 1551 | * |
| 1552 | * @returns true if the string matches an nVidia Tegra signature, and false otherwise |
| 1553 | */ |
| 1554 | static bool is_tegra(const char* start, const char* end) { |
| 1555 | /* Expect 5 ("tegra") or 6 ("tegra3") symbols */ |
| 1556 | const size_t length = end - start; |
| 1557 | switch (length) { |
| 1558 | case 5: |
| 1559 | case 6: |
| 1560 | break; |
| 1561 | default: |
| 1562 | return false; |
| 1563 | } |
| 1564 | |
| 1565 | /* Check that the first 5 characters match "tegra" */ |
| 1566 | if (start[0] != 't') { |
| 1567 | return false; |
| 1568 | } |
| 1569 | const uint32_t expected_egra = load_u32le(start + 1); |
| 1570 | if (expected_egra != UINT32_C(0x61726765) /* "arge" = reverse("egra") */) { |
| 1571 | return false; |
| 1572 | } |
| 1573 | |
| 1574 | /* Check if the string is either "tegra" (length = 5) or "tegra3" (length != 5) and last character is '3' */ |
| 1575 | return (length == 5 || start[5] == '3'); |
| 1576 | } |
| 1577 | |
| 1578 | struct special_map_entry { |
| 1579 | const char* platform; |
| 1580 | uint16_t model; |
| 1581 | uint8_t series; |
| 1582 | char suffix; |
| 1583 | }; |
| 1584 | |
| 1585 | static const struct special_map_entry special_hardware_map_entries[] = { |
| 1586 | { |
| 1587 | /* "k3v2oem1" -> HiSilicon K3V2 */ |
| 1588 | .platform = "k3v2oem1", |
| 1589 | .series = cpuinfo_arm_chipset_series_hisilicon_k3v, |
| 1590 | .model = 2, |
| 1591 | }, |
| 1592 | { |
| 1593 | /* "hi6620oem" -> HiSilicon Kirin 910T */ |
| 1594 | .platform = "hi6620oem", |
| 1595 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 1596 | .model = 910, |
| 1597 | .suffix = 'T' |
| 1598 | }, |
| 1599 | { |
| 1600 | /* "hi6250" -> HiSilicon Kirin 650 */ |
| 1601 | .platform = "hi6250", |
| 1602 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 1603 | .model = 650, |
| 1604 | }, |
| 1605 | { |
| 1606 | /* "hi6210sft" -> HiSilicon Kirin 620 */ |
| 1607 | .platform = "hi6210sft", |
| 1608 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 1609 | .model = 620, |
| 1610 | }, |
| 1611 | { |
| 1612 | /* "hi3751" -> HiSilicon Hi3751 */ |
| 1613 | .platform = "hi3751", |
| 1614 | .series = cpuinfo_arm_chipset_series_hisilicon_hi, |
| 1615 | .model = 3751, |
| 1616 | }, |
| 1617 | { |
| 1618 | /* "hi3635" -> HiSilicon Kirin 930 */ |
| 1619 | .platform = "hi3635", |
| 1620 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 1621 | .model = 930, |
| 1622 | }, |
| 1623 | { |
| 1624 | /* "hi3630" -> HiSilicon Kirin 920 */ |
| 1625 | .platform = "hi3630", |
| 1626 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 1627 | .model = 920, |
| 1628 | }, |
| 1629 | { |
| 1630 | /* "gs705a" -> Actions ATM7059A */ |
| 1631 | .platform = "gs705a", |
| 1632 | .series = cpuinfo_arm_chipset_series_actions_atm, |
| 1633 | .model = 7059, |
| 1634 | .suffix = 'A', |
| 1635 | }, |
| 1636 | { |
| 1637 | /* "gs702a" -> Actions ATM7029 */ |
| 1638 | .platform = "gs702a", |
| 1639 | .series = cpuinfo_arm_chipset_series_actions_atm, |
| 1640 | .model = 7029, |
| 1641 | }, |
| 1642 | { |
| 1643 | /* "gs702c" -> Actions ATM7029B */ |
| 1644 | .platform = "gs702c", |
| 1645 | .series = cpuinfo_arm_chipset_series_actions_atm, |
| 1646 | .model = 7029, |
| 1647 | .suffix = 'B' |
| 1648 | }, |
| 1649 | { |
| 1650 | /* "Amlogic Meson8" -> Amlogic S812 */ |
| 1651 | .platform = "Amlogic Meson8", |
| 1652 | .series = cpuinfo_arm_chipset_series_amlogic_s, |
| 1653 | .model = 812, |
| 1654 | }, |
| 1655 | { |
| 1656 | /* "Amlogic Meson8B" -> Amlogic S805 */ |
| 1657 | .platform = "Amlogic Meson8B", |
| 1658 | .series = cpuinfo_arm_chipset_series_amlogic_s, |
| 1659 | .model = 805, |
| 1660 | }, |
| 1661 | { |
| 1662 | /* "mapphone_CDMA" -> Texas Instruments OMAP4430 */ |
| 1663 | .platform = "mapphone_CDMA", |
| 1664 | .series = cpuinfo_arm_chipset_series_texas_instruments_omap, |
| 1665 | .model = 4430, |
| 1666 | }, |
| 1667 | { |
| 1668 | /* "Tuna" (Samsung Galaxy Nexus) -> Texas Instruments OMAP4460 */ |
| 1669 | .platform = "Tuna", |
| 1670 | .series = cpuinfo_arm_chipset_series_texas_instruments_omap, |
| 1671 | .model = 4460, |
| 1672 | }, |
| 1673 | { |
| 1674 | /* "Manta" (Samsung Nexus 10) -> Samsung Exynos 5250 */ |
| 1675 | .platform = "Manta", |
| 1676 | .series = cpuinfo_arm_chipset_series_samsung_exynos, |
| 1677 | .model = 5250, |
| 1678 | }, |
| 1679 | { |
| 1680 | /* "Odin" -> LG Nuclun 7111 */ |
| 1681 | .platform = "Odin", |
| 1682 | .series = cpuinfo_arm_chipset_series_lg_nuclun, |
| 1683 | .model = 7111, |
| 1684 | }, |
| 1685 | { |
| 1686 | /* "Madison" -> MStar 6A338 */ |
| 1687 | .platform = "Madison", |
| 1688 | .series = cpuinfo_arm_chipset_series_mstar_6a, |
| 1689 | .model = 338, |
| 1690 | }, |
| 1691 | }; |
| 1692 | |
| 1693 | static const struct special_map_entry tegra_hardware_map_entries[] = { |
| 1694 | { |
| 1695 | /* "cardhu" (nVidia Cardhu developer tablet) -> Tegra T30 */ |
| 1696 | .platform = "cardhu", |
| 1697 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1698 | .model = 30, |
| 1699 | }, |
| 1700 | { |
Marat Dukhan | 56b2403 | 2017-09-05 18:40:20 -0700 | [diff] [blame^] | 1701 | /* "kai" -> Tegra T30L */ |
| 1702 | .platform = "kai", |
| 1703 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1704 | .model = 30, |
| 1705 | .suffix = 'L', |
| 1706 | }, |
| 1707 | { |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1708 | /* "p3" (Samsung Galaxy Tab 8.9) -> Tegra T20 */ |
| 1709 | .platform = "p3", |
| 1710 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1711 | .model = 20, |
| 1712 | }, |
| 1713 | { |
Marat Dukhan | 56b2403 | 2017-09-05 18:40:20 -0700 | [diff] [blame^] | 1714 | /* "n1" (Samsung Galaxy R / Samsung Captivate Glide) -> Tegra AP20H */ |
| 1715 | .platform = "n1", |
| 1716 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_ap, |
| 1717 | .model = 20, |
| 1718 | .suffix = 'H', |
| 1719 | }, |
| 1720 | { |
| 1721 | /* "SHW-M380S" (Samsung Galaxy Tab 10.1) -> Tegra T20 */ |
| 1722 | .platform = "SHW-M380S", |
| 1723 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1724 | .model = 20, |
| 1725 | }, |
| 1726 | { |
| 1727 | /* "m470" (Hisense Sero 7 Pro) -> Tegra T30L */ |
| 1728 | .platform = "m470", |
| 1729 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1730 | .model = 30, |
| 1731 | .suffix = 'L', |
| 1732 | }, |
| 1733 | { |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1734 | /* "endeavoru" (HTC One X) -> Tegra AP33 */ |
| 1735 | .platform = "endeavoru", |
| 1736 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_ap, |
| 1737 | .model = 33, |
| 1738 | }, |
| 1739 | { |
| 1740 | /* "evitareul" (HTC One X+) -> Tegra T33 */ |
| 1741 | .platform = "evitareul", |
| 1742 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1743 | .model = 33, |
| 1744 | }, |
| 1745 | { |
| 1746 | /* "enrc2b" (HTC One X+) -> Tegra T33 */ |
| 1747 | .platform = "enrc2b", |
| 1748 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1749 | .model = 33, |
| 1750 | }, |
| 1751 | { |
| 1752 | /* "mozart" (Asus Transformer Pad TF701T) -> Tegra T114 */ |
| 1753 | .platform = "mozart", |
| 1754 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1755 | .model = 114, |
| 1756 | }, |
| 1757 | { |
Marat Dukhan | 56b2403 | 2017-09-05 18:40:20 -0700 | [diff] [blame^] | 1758 | /* "tegratab" (Tegra Note 7) -> Tegra T114 */ |
| 1759 | .platform = "tegratab", |
| 1760 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1761 | .model = 114, |
| 1762 | }, |
| 1763 | { |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1764 | /* "tn8" (nVidia Shield Tablet K1) -> Tegra T124 */ |
| 1765 | .platform = "tn8", |
| 1766 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1767 | .model = 124, |
| 1768 | }, |
| 1769 | { |
Marat Dukhan | 56b2403 | 2017-09-05 18:40:20 -0700 | [diff] [blame^] | 1770 | /* "roth" (nVidia Shield Portable) -> Tegra T114 */ |
| 1771 | .platform = "roth", |
| 1772 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1773 | .model = 114, |
| 1774 | }, |
| 1775 | { |
| 1776 | /* "foster_e" (nVidia Shield TV, Flash) -> Tegra T210 */ |
| 1777 | .platform = "foster_e", |
| 1778 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1779 | .model = 210, |
| 1780 | }, |
| 1781 | { |
| 1782 | /* "foster_e_hdd" (nVidia Shield TV, HDD) -> Tegra T210 */ |
| 1783 | .platform = "foster_e_hdd", |
| 1784 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1785 | .model = 210, |
| 1786 | }, |
| 1787 | { |
| 1788 | /* "darcy" (nVidia Shield TV 2017) -> Tegra T210 */ |
| 1789 | .platform = "darcy", |
| 1790 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1791 | .model = 210, |
| 1792 | }, |
| 1793 | { |
| 1794 | /* "pisces" (Xiaomi Mi 3) -> Tegra T114 */ |
| 1795 | .platform = "pisces", |
| 1796 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1797 | .model = 114, |
| 1798 | }, |
| 1799 | { |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1800 | /* "mocha" (Xiaomi Mi Pad) -> Tegra T124 */ |
| 1801 | .platform = "mocha", |
| 1802 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1803 | .model = 124, |
| 1804 | }, |
| 1805 | { |
| 1806 | /* "stingray" (Motorola XOOM) -> Tegra AP20H */ |
| 1807 | .platform = "stingray", |
| 1808 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_ap, |
| 1809 | .model = 20, |
| 1810 | .suffix = 'H', |
| 1811 | }, |
| 1812 | { |
| 1813 | /* "Ceres" (Wiko Highway 4G) -> Tegra SL460N */ |
| 1814 | .platform = "Ceres", |
| 1815 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_sl, |
| 1816 | .model = 460, |
| 1817 | .suffix = 'N', |
| 1818 | }, |
| 1819 | { |
Marat Dukhan | 56b2403 | 2017-09-05 18:40:20 -0700 | [diff] [blame^] | 1820 | /* "MT799" (nabi 2 Tablet) -> Tegra T30 */ |
| 1821 | .platform = "MT799", |
| 1822 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1823 | .model = 30, |
| 1824 | }, |
| 1825 | { |
| 1826 | /* "t8400n" (nabi DreamTab HD8) -> Tegra T114 */ |
| 1827 | .platform = "t8400n", |
| 1828 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1829 | .model = 114, |
| 1830 | }, |
| 1831 | { |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1832 | /* "chagall" (Fujitsu Stylistic M532) -> Tegra T30 */ |
| 1833 | .platform = "chagall", |
| 1834 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1835 | .model = 30, |
| 1836 | }, |
| 1837 | { |
| 1838 | /* "ventana" (Asus Transformer TF101) -> Tegra T20 */ |
| 1839 | .platform = "ventana", |
| 1840 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1841 | .model = 20, |
| 1842 | }, |
| 1843 | { |
| 1844 | /* "bobsleigh" (Fujitsu Arrows Tab F-05E) -> Tegra T33 */ |
| 1845 | .platform = "bobsleigh", |
| 1846 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1847 | .model = 33, |
| 1848 | }, |
| 1849 | { |
Marat Dukhan | 56b2403 | 2017-09-05 18:40:20 -0700 | [diff] [blame^] | 1850 | /* "tegra_fjdev101" (Fujitsu Arrows X F-10D) -> Tegra AP33 */ |
| 1851 | .platform = "tegra_fjdev101", |
| 1852 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_ap, |
| 1853 | .model = 33, |
| 1854 | }, |
| 1855 | { |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1856 | /* "tegra_fjdev103" (Fujitsu Arrows V F-04E) -> Tegra T33 */ |
| 1857 | .platform = "tegra_fjdev103", |
| 1858 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1859 | .model = 33, |
| 1860 | }, |
| 1861 | { |
| 1862 | /* "nbx03" (Sony Tablet S) -> Tegra T20 */ |
| 1863 | .platform = "nbx03", |
| 1864 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1865 | .model = 20, |
| 1866 | }, |
| 1867 | { |
| 1868 | /* "txs03" (Sony Xperia Tablet S) -> Tegra T30L */ |
| 1869 | .platform = "txs03", |
| 1870 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1871 | .model = 30, |
| 1872 | .suffix = 'L', |
| 1873 | }, |
| 1874 | { |
| 1875 | /* "x3" (LG Optimus 4X HD P880) -> Tegra AP33 */ |
| 1876 | .platform = "x3", |
| 1877 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_ap, |
| 1878 | .model = 33, |
| 1879 | }, |
| 1880 | { |
Marat Dukhan | 56b2403 | 2017-09-05 18:40:20 -0700 | [diff] [blame^] | 1881 | /* "vu10" (LG Optimus Vu P895) -> Tegra AP33 */ |
| 1882 | .platform = "vu10", |
| 1883 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_ap, |
| 1884 | .model = 33, |
| 1885 | }, |
| 1886 | { |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1887 | /* "BIRCH" (HP Slate 7 Plus) -> Tegra T30L */ |
| 1888 | .platform = "BIRCH", |
| 1889 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1890 | .model = 30, |
| 1891 | .suffix = 'L', |
| 1892 | }, |
| 1893 | { |
| 1894 | /* "macallan" (HP Slate 8 Pro) -> Tegra T114 */ |
| 1895 | .platform = "macallan", |
| 1896 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1897 | .model = 114, |
| 1898 | }, |
| 1899 | { |
Marat Dukhan | 56b2403 | 2017-09-05 18:40:20 -0700 | [diff] [blame^] | 1900 | /* "maya" (HP SlateBook 10 x2) -> Tegra T114 */ |
| 1901 | .platform = "maya", |
| 1902 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1903 | .model = 114, |
| 1904 | }, |
| 1905 | { |
| 1906 | /* "antares" (Toshiba AT100) -> Tegra T20 */ |
| 1907 | .platform = "antares", |
| 1908 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1909 | .model = 20, |
| 1910 | }, |
| 1911 | { |
| 1912 | /* "tostab12AL" (Toshiba AT300SE "Excite 10 SE") -> Tegra T30L */ |
| 1913 | .platform = "tostab12AL", |
| 1914 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1915 | .model = 30, |
| 1916 | .suffix = 'L', |
| 1917 | }, |
| 1918 | { |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1919 | /* "tostab12BL" (Toshiba AT10-A "Excite Pure") -> Tegra T30L */ |
| 1920 | .platform = "tostab12BL", |
| 1921 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1922 | .model = 30, |
| 1923 | .suffix = 'L', |
| 1924 | }, |
| 1925 | { |
Marat Dukhan | 56b2403 | 2017-09-05 18:40:20 -0700 | [diff] [blame^] | 1926 | /* "sphinx" (Toshiba AT270 "Excite 7.7") -> Tegra T30 */ |
| 1927 | .platform = "sphinx", |
| 1928 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1929 | .model = 30, |
| 1930 | }, |
| 1931 | { |
| 1932 | /* "tostab11BS" (Toshiba AT570 "Regza 7.7") -> Tegra T30 */ |
| 1933 | .platform = "tostab11BS", |
| 1934 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1935 | .model = 30, |
| 1936 | }, |
| 1937 | { |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1938 | /* "tostab12BA" (Toshiba AT10-LE-A "Excite Pro") -> Tegra T114 */ |
| 1939 | .platform = "tostab12BA", |
| 1940 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1941 | .model = 114, |
| 1942 | }, |
| 1943 | { |
Marat Dukhan | 56b2403 | 2017-09-05 18:40:20 -0700 | [diff] [blame^] | 1944 | /* "vangogh" (Acer Iconia Tab A100) -> Tegra T20 */ |
| 1945 | .platform = "vangogh", |
| 1946 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1947 | .model = 20, |
Marat Dukhan | 56b2403 | 2017-09-05 18:40:20 -0700 | [diff] [blame^] | 1948 | }, |
| 1949 | { |
| 1950 | /* "a110" (Acer Iconia Tab A110) -> Tegra T30L */ |
| 1951 | .platform = "a110", |
| 1952 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1953 | .model = 30, |
| 1954 | .suffix = 'L', |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1955 | }, |
| 1956 | { |
| 1957 | /* "picasso_e" (Acer Iconia Tab A200) -> Tegra AP20H */ |
| 1958 | .platform = "picasso_e", |
| 1959 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_ap, |
| 1960 | .model = 20, |
| 1961 | .suffix = 'H', |
| 1962 | }, |
| 1963 | { |
| 1964 | /* "picasso_e2" (Acer Iconia Tab A210) -> Tegra T30L */ |
| 1965 | .platform = "picasso_e2", |
| 1966 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1967 | .model = 30, |
| 1968 | .suffix = 'L', |
| 1969 | }, |
| 1970 | { |
Marat Dukhan | 56b2403 | 2017-09-05 18:40:20 -0700 | [diff] [blame^] | 1971 | /* "picasso" (Acer Iconia Tab A500) -> Tegra AP20H */ |
| 1972 | .platform = "picasso", |
| 1973 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_ap, |
| 1974 | .model = 20, |
| 1975 | .suffix = 'H', |
| 1976 | }, |
| 1977 | { |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1978 | /* "picasso_m" (Acer Iconia Tab A510) -> Tegra T30 */ |
| 1979 | .platform = "picasso_m", |
| 1980 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1981 | .model = 30, |
| 1982 | }, |
| 1983 | { |
| 1984 | /* "picasso_mf" (Acer Iconia Tab A700) -> Tegra T30 */ |
| 1985 | .platform = "picasso_mf", |
| 1986 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1987 | .model = 30, |
| 1988 | }, |
| 1989 | { |
| 1990 | /* "avalon" (Toshiba AT300 "Excite 10") -> Tegra T30L */ |
| 1991 | .platform = "avalon", |
| 1992 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1993 | .model = 30, |
| 1994 | .suffix = 'L', |
| 1995 | }, |
| 1996 | { |
| 1997 | /* "NS_14T004" (iRiver NS-14T004) -> Tegra T30L */ |
| 1998 | .platform = "NS_14T004", |
| 1999 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 2000 | .model = 30, |
| 2001 | .suffix = 'L', |
| 2002 | }, |
Marat Dukhan | 56b2403 | 2017-09-05 18:40:20 -0700 | [diff] [blame^] | 2003 | { |
| 2004 | /* "WIKIPAD" (Wikipad) -> Tegra T30 */ |
| 2005 | .platform = "WIKIPAD", |
| 2006 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 2007 | .model = 30, |
| 2008 | }, |
| 2009 | { |
| 2010 | /* "kb" (Pegatron Q00Q) -> Tegra T114 */ |
| 2011 | .platform = "kb", |
| 2012 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 2013 | .model = 114, |
| 2014 | }, |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 2015 | }; |
| 2016 | |
| 2017 | /* |
| 2018 | * Decodes chipset name from /proc/cpuinfo Hardware string. |
| 2019 | * For some chipsets, the function relies frequency and on number of cores for chipset detection. |
| 2020 | * |
| 2021 | * @param[in] platform - /proc/cpuinfo Hardware string. |
| 2022 | * @param cores - number of cores in the chipset. |
| 2023 | * @param max_cpu_freq_max - maximum of /sys/devices/system/cpu/cpu<number>/cpofreq/cpu_freq_max values. |
| 2024 | * |
| 2025 | * @returns Decoded chipset name. If chipset could not be decoded, the resulting structure would use `unknown` vendor |
| 2026 | * and series identifiers. |
| 2027 | */ |
| 2028 | struct cpuinfo_arm_chipset cpuinfo_arm_android_decode_chipset_from_proc_cpuinfo_hardware( |
| 2029 | const char hardware[restrict static CPUINFO_HARDWARE_VALUE_MAX], |
| 2030 | uint32_t cores, uint32_t max_cpu_freq_max, bool is_tegra) |
| 2031 | { |
| 2032 | struct cpuinfo_arm_chipset chipset; |
| 2033 | const size_t hardware_length = strnlen(hardware, CPUINFO_HARDWARE_VALUE_MAX); |
| 2034 | const char* hardware_end = hardware + hardware_length; |
| 2035 | |
| 2036 | if (is_tegra) { |
| 2037 | /* |
| 2038 | * nVidia Tegra-specific path: compare /proc/cpuinfo Hardware string to |
| 2039 | * tabulated Hardware values for popular chipsets/devices with Tegra chipsets. |
| 2040 | * This path is only used when ro.board.platform indicates a Tegra chipset |
| 2041 | * (albeit does not indicate which exactly Tegra chipset). |
| 2042 | */ |
| 2043 | for (size_t i = 0; i < CPUINFO_COUNT_OF(tegra_hardware_map_entries); i++) { |
| 2044 | if (strncmp(tegra_hardware_map_entries[i].platform, hardware, hardware_length) == 0 && |
| 2045 | tegra_hardware_map_entries[i].platform[hardware_length] == 0) |
| 2046 | { |
| 2047 | cpuinfo_log_debug( |
| 2048 | "found /proc/cpuinfo Hardware string \"%.*s\" in nVidia Tegra chipset table", |
| 2049 | (int) hardware_length, hardware); |
| 2050 | /* Create chipset name from entry */ |
| 2051 | return (struct cpuinfo_arm_chipset) { |
| 2052 | .vendor = chipset_series_vendor[tegra_hardware_map_entries[i].series], |
| 2053 | .series = (enum cpuinfo_arm_chipset_series) tegra_hardware_map_entries[i].series, |
| 2054 | .model = tegra_hardware_map_entries[i].model, |
| 2055 | .suffix = { |
| 2056 | [0] = tegra_hardware_map_entries[i].suffix, |
| 2057 | }, |
| 2058 | }; |
| 2059 | } |
| 2060 | } |
| 2061 | } else { |
| 2062 | /* Generic path: consider all other vendors */ |
| 2063 | |
| 2064 | bool word_start = true; |
| 2065 | for (const char* pos = hardware; pos != hardware_end; pos++) { |
| 2066 | const char c = *pos; |
| 2067 | switch (c) { |
| 2068 | case ' ': |
| 2069 | case '\t': |
| 2070 | case ',': |
| 2071 | word_start = true; |
| 2072 | break; |
| 2073 | default: |
| 2074 | if (word_start && is_ascii_alphabetic(c)) { |
| 2075 | /* Check Qualcomm MSM/APQ signature */ |
| 2076 | if (match_msm_apq(pos, hardware_end, &chipset)) { |
| 2077 | cpuinfo_log_debug( |
| 2078 | "matched Qualcomm MSM/APQ signature in /proc/cpuinfo Hardware string \"%.*s\"", |
| 2079 | (int) hardware_length, hardware); |
| 2080 | return chipset; |
| 2081 | } |
| 2082 | |
| 2083 | /* Check SDMxxx (Qualcomm Snapdragon) signature */ |
| 2084 | if (match_sdm(pos, hardware_end, &chipset)) { |
| 2085 | cpuinfo_log_debug( |
| 2086 | "matched Qualcomm SDM signature in /proc/cpuinfo Hardware string \"%.*s\"", |
| 2087 | (int) hardware_length, hardware); |
| 2088 | return chipset; |
| 2089 | } |
| 2090 | |
| 2091 | /* Check MediaTek MT signature */ |
| 2092 | if (match_mt(pos, hardware_end, true, &chipset)) { |
| 2093 | cpuinfo_log_debug( |
| 2094 | "matched MediaTek MT signature in /proc/cpuinfo Hardware string \"%.*s\"", |
| 2095 | (int) hardware_length, hardware); |
| 2096 | return chipset; |
| 2097 | } |
| 2098 | |
| 2099 | /* Check HiSilicon Kirin signature */ |
| 2100 | if (match_kirin(pos, hardware_end, &chipset)) { |
| 2101 | cpuinfo_log_debug( |
| 2102 | "matched HiSilicon Kirin signature in /proc/cpuinfo Hardware string \"%.*s\"", |
| 2103 | (int) hardware_length, hardware); |
| 2104 | return chipset; |
| 2105 | } |
| 2106 | |
| 2107 | /* Check Rockchip RK signature */ |
| 2108 | if (match_rk(pos, hardware_end, &chipset)) { |
| 2109 | cpuinfo_log_debug( |
| 2110 | "matched Rockchip RK signature in /proc/cpuinfo Hardware string \"%.*s\"", |
| 2111 | (int) hardware_length, hardware); |
| 2112 | return chipset; |
| 2113 | } |
| 2114 | } |
| 2115 | word_start = false; |
| 2116 | break; |
| 2117 | } |
| 2118 | } |
| 2119 | |
| 2120 | /* Check Samsung Exynos signature */ |
| 2121 | if (match_samsung_exynos(hardware, hardware_end, &chipset)) { |
| 2122 | cpuinfo_log_debug( |
| 2123 | "matched Samsung Exynos signature in /proc/cpuinfo Hardware string \"%.*s\"", |
| 2124 | (int) hardware_length, hardware); |
| 2125 | return chipset; |
| 2126 | } |
| 2127 | |
| 2128 | /* Check universalXXXX (Samsung Exynos) signature */ |
| 2129 | if (match_universal(hardware, hardware_end, &chipset)) { |
| 2130 | cpuinfo_log_debug( |
| 2131 | "matched UNIVERSAL (Samsung Exynos) signature in /proc/cpuinfo Hardware string \"%.*s\"", |
| 2132 | (int) hardware_length, hardware); |
| 2133 | return chipset; |
| 2134 | } |
| 2135 | |
| 2136 | /* Match /SMDK(4410|4x12)$/ */ |
| 2137 | if (match_and_parse_smdk(hardware, hardware_end, cores, &chipset)) { |
| 2138 | cpuinfo_log_debug( |
| 2139 | "matched SMDK (Samsung Exynos) signature in /proc/cpuinfo Hardware string \"%.*s\"", |
| 2140 | (int) hardware_length, hardware); |
| 2141 | return chipset; |
| 2142 | } |
| 2143 | |
| 2144 | /* Check Spreadtrum SC signature */ |
| 2145 | if (match_sc(hardware, hardware_end, &chipset)) { |
| 2146 | cpuinfo_log_debug( |
| 2147 | "matched Spreadtrum SC signature in /proc/cpuinfo Hardware string \"%.*s\"", |
| 2148 | (int) hardware_length, hardware); |
| 2149 | return chipset; |
| 2150 | } |
| 2151 | |
| 2152 | /* Check Marvell PXA signature */ |
| 2153 | if (match_pxa(hardware, hardware_end, &chipset)) { |
| 2154 | cpuinfo_log_debug( |
| 2155 | "matched Marvell PXA signature in /proc/cpuinfo Hardware string \"%.*s\"", |
| 2156 | (int) hardware_length, hardware); |
| 2157 | return chipset; |
| 2158 | } |
| 2159 | |
| 2160 | /* Match /sun\d+i/ signature and map to Allwinner chipset name */ |
| 2161 | if (match_and_parse_sunxi(hardware, hardware_end, cores, &chipset)) { |
| 2162 | cpuinfo_log_debug( |
| 2163 | "matched sunxi (Allwinner Ax) signature in /proc/cpuinfo Hardware string \"%.*s\"", |
| 2164 | (int) hardware_length, hardware); |
| 2165 | return chipset; |
| 2166 | } |
| 2167 | |
| 2168 | /* Check Texas Instruments OMAP signature */ |
| 2169 | if (match_omap(hardware, hardware_end, &chipset)) { |
| 2170 | cpuinfo_log_debug( |
| 2171 | "matched Texas Instruments OMAP signature in /proc/cpuinfo Hardware string \"%.*s\"", |
| 2172 | (int) hardware_length, hardware); |
| 2173 | return chipset; |
| 2174 | } |
| 2175 | |
| 2176 | /* Check WonderMedia WMT signature and decode chipset from frequency and number of cores */ |
| 2177 | if (match_and_parse_wmt(hardware, hardware_end, cores, max_cpu_freq_max, &chipset)) { |
| 2178 | cpuinfo_log_debug( |
| 2179 | "matched WonderMedia WMT signature in /proc/cpuinfo Hardware string \"%.*s\"", |
| 2180 | (int) hardware_length, hardware); |
| 2181 | return chipset; |
| 2182 | } |
| 2183 | |
| 2184 | /* Check Telechips TCC signature */ |
| 2185 | if (match_tcc(hardware, hardware_end, &chipset)) { |
| 2186 | cpuinfo_log_debug( |
| 2187 | "matched Telechips TCC signature in /proc/cpuinfo Hardware string \"%.*s\"", |
| 2188 | (int) hardware_length, hardware); |
| 2189 | return chipset; |
| 2190 | } |
| 2191 | |
| 2192 | /* Compare to tabulated Hardware values for popular chipsets/devices which can't be otherwise detected */ |
| 2193 | for (size_t i = 0; i < CPUINFO_COUNT_OF(special_hardware_map_entries); i++) { |
| 2194 | if (strncmp(special_hardware_map_entries[i].platform, hardware, hardware_length) == 0 && |
| 2195 | special_hardware_map_entries[i].platform[hardware_length] == 0) |
| 2196 | { |
| 2197 | cpuinfo_log_debug( |
| 2198 | "found /proc/cpuinfo Hardware string \"%.*s\" in special chipset table", |
| 2199 | (int) hardware_length, hardware); |
| 2200 | /* Create chipset name from entry */ |
| 2201 | return (struct cpuinfo_arm_chipset) { |
| 2202 | .vendor = chipset_series_vendor[special_hardware_map_entries[i].series], |
| 2203 | .series = (enum cpuinfo_arm_chipset_series) special_hardware_map_entries[i].series, |
| 2204 | .model = special_hardware_map_entries[i].model, |
| 2205 | .suffix = { |
| 2206 | [0] = special_hardware_map_entries[i].suffix, |
| 2207 | }, |
| 2208 | }; |
| 2209 | } |
| 2210 | } |
| 2211 | } |
| 2212 | |
| 2213 | return (struct cpuinfo_arm_chipset) { |
| 2214 | .vendor = cpuinfo_arm_chipset_vendor_unknown, |
| 2215 | .series = cpuinfo_arm_chipset_series_unknown, |
| 2216 | }; |
| 2217 | } |
| 2218 | |
| 2219 | static const struct special_map_entry special_board_map_entries[] = { |
| 2220 | { |
| 2221 | /* "hi6250" -> HiSilicon Kirin 650 */ |
| 2222 | .platform = "hi6250", |
| 2223 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2224 | .model = 650, |
| 2225 | }, |
| 2226 | { |
| 2227 | /* "hi6210sft" -> HiSilicon Kirin 620 */ |
| 2228 | .platform = "hi6210sft", |
| 2229 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2230 | .model = 620, |
| 2231 | }, |
| 2232 | { |
| 2233 | /* "hi3650" -> HiSilicon Kirin 950 */ |
| 2234 | .platform = "hi3650", |
| 2235 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2236 | .model = 950, |
| 2237 | }, |
| 2238 | { |
| 2239 | /* "hi3635" -> HiSilicon Kirin 930 */ |
| 2240 | .platform = "hi3635", |
| 2241 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2242 | .model = 930, |
| 2243 | }, |
| 2244 | { |
| 2245 | /* "hi3630" -> HiSilicon Kirin 920 */ |
| 2246 | .platform = "hi3630", |
| 2247 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2248 | .model = 920, |
| 2249 | }, |
| 2250 | { |
| 2251 | /* "mp523x" -> Renesas MP5232 */ |
| 2252 | .platform = "mp523x", |
| 2253 | .series = cpuinfo_arm_chipset_series_renesas_mp, |
| 2254 | .model = 5232, |
| 2255 | }, |
| 2256 | { |
| 2257 | /* "piranha" -> Texas Instruments OMAP4430 */ |
| 2258 | .platform = "piranha", |
| 2259 | .series = cpuinfo_arm_chipset_series_texas_instruments_omap, |
| 2260 | .model = 4430, |
| 2261 | }, |
| 2262 | { |
| 2263 | /* "BEETHOVEN" (Huawei MadiaPad M3) -> HiSilicon Kirin 950 */ |
| 2264 | .platform = "BEETHOVEN", |
| 2265 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2266 | .model = 950, |
| 2267 | }, |
| 2268 | { |
| 2269 | /* "hws7701u" (Huawei MediaPad 7 Youth) -> Rockchip RK3168 */ |
| 2270 | .platform = "hws7701u", |
| 2271 | .series = cpuinfo_arm_chipset_series_rockchip_rk, |
| 2272 | .model = 3168, |
| 2273 | }, |
| 2274 | { |
| 2275 | /* "g2mv" (LG G2 mini LTE) -> nVidia Tegra SL460N */ |
| 2276 | .platform = "g2mv", |
| 2277 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_sl, |
| 2278 | .model = 460, |
| 2279 | .suffix = 'N', |
| 2280 | }, |
| 2281 | { |
| 2282 | /* "K00F" (Asus MeMO Pad 10) -> Rockchip RK3188 */ |
| 2283 | .platform = "K00F", |
| 2284 | .series = cpuinfo_arm_chipset_series_rockchip_rk, |
| 2285 | .model = 3188, |
| 2286 | }, |
| 2287 | { |
| 2288 | /* "T7H" (HP Slate 7) -> Rockchip RK3066 */ |
| 2289 | .platform = "T7H", |
| 2290 | .series = cpuinfo_arm_chipset_series_rockchip_rk, |
| 2291 | .model = 3066, |
| 2292 | }, |
| 2293 | { |
| 2294 | /* "tuna" (Samsung Galaxy Nexus) -> Texas Instruments OMAP4460 */ |
| 2295 | .platform = "tuna", |
| 2296 | .series = cpuinfo_arm_chipset_series_texas_instruments_omap, |
| 2297 | .model = 4460, |
| 2298 | }, |
| 2299 | { |
| 2300 | /* "grouper" (Asus Nexus 7 2012) -> nVidia Tegra T30L */ |
| 2301 | .platform = "grouper", |
| 2302 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 2303 | .model = 30, |
| 2304 | .suffix = 'L', |
| 2305 | }, |
| 2306 | { |
| 2307 | /* "flounder" (HTC Nexus 9) -> nVidia Tegra T132 */ |
| 2308 | .platform = "flounder", |
| 2309 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 2310 | .model = 132, |
| 2311 | }, |
| 2312 | { |
| 2313 | /* "dragon" (Google Pixel C) -> nVidia Tegra T210 */ |
| 2314 | .platform = "dragon", |
| 2315 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 2316 | .model = 210, |
| 2317 | }, |
| 2318 | { |
| 2319 | /* "sailfish" (Google Pixel) -> Qualcomm MSM8996PRO */ |
| 2320 | .platform = "sailfish", |
| 2321 | .series = cpuinfo_arm_chipset_series_qualcomm_msm, |
| 2322 | .model = 8996, |
| 2323 | .suffix = 'P', |
| 2324 | }, |
| 2325 | { |
| 2326 | /* "marlin" (Google Pixel XL) -> Qualcomm MSM8996PRO */ |
| 2327 | .platform = "marlin", |
| 2328 | .series = cpuinfo_arm_chipset_series_qualcomm_msm, |
| 2329 | .model = 8996, |
| 2330 | .suffix = 'P', |
| 2331 | }, |
| 2332 | }; |
| 2333 | |
| 2334 | /* |
| 2335 | * Decodes chipset name from ro.product.board Android system property. |
| 2336 | * For some chipsets, the function relies frequency and on number of cores for chipset detection. |
| 2337 | * |
| 2338 | * @param[in] platform - ro.product.board value. |
| 2339 | * @param cores - number of cores in the chipset. |
| 2340 | * @param max_cpu_freq_max - maximum of /sys/devices/system/cpu/cpu<number>/cpofreq/cpu_freq_max values. |
| 2341 | * |
| 2342 | * @returns Decoded chipset name. If chipset could not be decoded, the resulting structure would use `unknown` vendor |
| 2343 | * and series identifiers. |
| 2344 | */ |
| 2345 | struct cpuinfo_arm_chipset cpuinfo_arm_android_decode_chipset_from_ro_product_board( |
| 2346 | const char ro_product_board[restrict static CPUINFO_BUILD_PROP_VALUE_MAX], |
| 2347 | uint32_t cores, uint32_t max_cpu_freq_max) |
| 2348 | { |
| 2349 | struct cpuinfo_arm_chipset chipset; |
| 2350 | const char* board = ro_product_board; |
| 2351 | const size_t board_length = strnlen(ro_product_board, CPUINFO_BUILD_PROP_VALUE_MAX); |
| 2352 | const char* board_end = ro_product_board + board_length; |
| 2353 | |
| 2354 | /* Check Qualcomm MSM/APQ signature */ |
| 2355 | if (match_msm_apq(board, board_end, &chipset)) { |
| 2356 | cpuinfo_log_debug( |
| 2357 | "matched Qualcomm MSM/APQ signature in ro.product.board string \"%.*s\"", (int) board_length, board); |
| 2358 | return chipset; |
| 2359 | } |
| 2360 | |
| 2361 | /* Check universaXXXX (Samsung Exynos) signature */ |
| 2362 | if (match_universal(board, board_end, &chipset)) { |
| 2363 | cpuinfo_log_debug( |
| 2364 | "matched UNIVERSAL (Samsung Exynos) signature in ro.product.board string \"%.*s\"", |
| 2365 | (int) board_length, board); |
| 2366 | return chipset; |
| 2367 | } |
| 2368 | |
| 2369 | /* Check SMDK (Samsung Exynos) signature */ |
| 2370 | if (match_and_parse_smdk(board, board_end, cores, &chipset)) { |
| 2371 | cpuinfo_log_debug( |
| 2372 | "matched SMDK (Samsung Exynos) signature in ro.product.board string \"%.*s\"", |
| 2373 | (int) board_length, board); |
| 2374 | return chipset; |
| 2375 | } |
| 2376 | |
| 2377 | /* Check MediaTek MT signature */ |
| 2378 | if (match_mt(board, board_end, true, &chipset)) { |
| 2379 | cpuinfo_log_debug( |
| 2380 | "matched MediaTek MT signature in ro.product.board string \"%.*s\"", |
| 2381 | (int) board_length, board); |
| 2382 | return chipset; |
| 2383 | } |
| 2384 | |
| 2385 | /* Check Spreadtrum SC signature */ |
| 2386 | if (match_sc(board, board_end, &chipset)) { |
| 2387 | cpuinfo_log_debug( |
| 2388 | "matched Spreadtrum SC signature in ro.product.board string \"%.*s\"", |
| 2389 | (int) board_length, board); |
| 2390 | return chipset; |
| 2391 | } |
| 2392 | |
| 2393 | /* Check Marvell PXA signature */ |
| 2394 | if (match_pxa(board, board_end, &chipset)) { |
| 2395 | cpuinfo_log_debug( |
| 2396 | "matched Marvell PXA signature in ro.product.board string \"%.*s\"", |
| 2397 | (int) board_length, board); |
| 2398 | return chipset; |
| 2399 | } |
| 2400 | |
| 2401 | /* Check Leadcore LCxxxx signature */ |
| 2402 | if (match_lc(board, board_end, &chipset)) { |
| 2403 | cpuinfo_log_debug( |
| 2404 | "matched Leadcore LC signature in ro.product.board string \"%.*s\"", |
| 2405 | (int) board_length, board); |
| 2406 | return chipset; |
| 2407 | } |
| 2408 | |
| 2409 | /* |
| 2410 | * Compare to tabulated ro.product.board values for Broadcom chipsets and decode chipset from frequency and |
| 2411 | * number of cores. |
| 2412 | */ |
| 2413 | if (match_and_parse_broadcom(board, board_end, cores, max_cpu_freq_max, &chipset)) { |
| 2414 | cpuinfo_log_debug( |
| 2415 | "found ro.product.board string \"%.*s\" in Broadcom chipset table", |
| 2416 | (int) board_length, board); |
| 2417 | return chipset; |
| 2418 | } |
| 2419 | |
| 2420 | /* Compare to tabulated ro.product.board values for Huawei devices which don't report chipset elsewhere */ |
| 2421 | if (match_and_parse_huawei(board, board_end, &chipset)) { |
| 2422 | cpuinfo_log_debug( |
| 2423 | "found ro.product.board string \"%.*s\" in Huawei chipset table", |
| 2424 | (int) board_length, board); |
| 2425 | return chipset; |
| 2426 | } |
| 2427 | |
| 2428 | /* Compare to tabulated ro.product.board values for popular chipsets/devices which can't be otherwise detected */ |
| 2429 | for (size_t i = 0; i < CPUINFO_COUNT_OF(special_board_map_entries); i++) { |
| 2430 | if (strncmp(special_board_map_entries[i].platform, board, board_length) == 0 && |
| 2431 | special_board_map_entries[i].platform[board_length] == 0) |
| 2432 | { |
| 2433 | cpuinfo_log_debug( |
| 2434 | "found ro.product.board string \"%.*s\" in special chipset table", |
| 2435 | (int) board_length, board); |
| 2436 | /* Create chipset name from entry */ |
| 2437 | return (struct cpuinfo_arm_chipset) { |
| 2438 | .vendor = chipset_series_vendor[special_board_map_entries[i].series], |
| 2439 | .series = (enum cpuinfo_arm_chipset_series) special_board_map_entries[i].series, |
| 2440 | .model = special_board_map_entries[i].model, |
| 2441 | .suffix = { |
| 2442 | [0] = special_board_map_entries[i].suffix, |
| 2443 | /* The suffix of MSM8996PRO is truncated at the first letter, reconstruct it here. */ |
| 2444 | [1] = special_board_map_entries[i].suffix == 'P' ? 'R' : 0, |
| 2445 | [2] = special_board_map_entries[i].suffix == 'P' ? 'O' : 0, |
| 2446 | }, |
| 2447 | }; |
| 2448 | } |
| 2449 | } |
| 2450 | |
| 2451 | return (struct cpuinfo_arm_chipset) { |
| 2452 | .vendor = cpuinfo_arm_chipset_vendor_unknown, |
| 2453 | .series = cpuinfo_arm_chipset_series_unknown, |
| 2454 | }; |
| 2455 | } |
| 2456 | |
| 2457 | struct amlogic_map_entry { |
| 2458 | char ro_board_platform[6]; |
| 2459 | uint16_t model; |
| 2460 | uint8_t series; |
| 2461 | char suffix[3]; |
| 2462 | }; |
| 2463 | |
| 2464 | static const struct amlogic_map_entry amlogic_map_entries[] = { |
| 2465 | { |
| 2466 | /* "meson3" -> Amlogic AML8726-M */ |
| 2467 | .ro_board_platform = "meson3", |
| 2468 | .series = cpuinfo_arm_chipset_series_amlogic_aml, |
| 2469 | .model = 8726, |
| 2470 | .suffix = "-M", |
| 2471 | }, |
| 2472 | { |
| 2473 | /* "meson6" -> Amlogic AML8726-MX */ |
| 2474 | .ro_board_platform = "meson6", |
| 2475 | .series = cpuinfo_arm_chipset_series_amlogic_aml, |
| 2476 | .model = 8726, |
| 2477 | .suffix = "-MX", |
| 2478 | }, |
| 2479 | { |
| 2480 | /* "meson8" -> Amlogic S805 */ |
| 2481 | .ro_board_platform = "meson8", |
| 2482 | .series = cpuinfo_arm_chipset_series_amlogic_s, |
| 2483 | .model = 805, |
| 2484 | }, |
| 2485 | { |
| 2486 | /* "gxbaby" -> Amlogic S905 */ |
| 2487 | .ro_board_platform = "gxbaby", |
| 2488 | .series = cpuinfo_arm_chipset_series_amlogic_s, |
| 2489 | .model = 905, |
| 2490 | }, |
| 2491 | { |
| 2492 | /* "gxl" -> Amlogic S905X */ |
| 2493 | .ro_board_platform = "gxl", |
| 2494 | .series = cpuinfo_arm_chipset_series_amlogic_s, |
| 2495 | .model = 905, |
| 2496 | .suffix = "X", |
| 2497 | }, |
| 2498 | { |
| 2499 | /* "gxm" -> Amlogic S912 */ |
| 2500 | .ro_board_platform = "gxm", |
| 2501 | .series = cpuinfo_arm_chipset_series_amlogic_s, |
| 2502 | .model = 912, |
| 2503 | }, |
| 2504 | }; |
| 2505 | |
| 2506 | static const struct special_map_entry special_platform_map_entries[] = { |
| 2507 | { |
| 2508 | /* "hi6620oem" -> HiSilicon Kirin 910T */ |
| 2509 | .platform = "hi6620oem", |
| 2510 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2511 | .model = 910, |
| 2512 | .suffix = 'T', |
| 2513 | }, |
| 2514 | { |
| 2515 | /* "hi6250" -> HiSilicon Kirin 650 */ |
| 2516 | .platform = "hi6250", |
| 2517 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2518 | .model = 650, |
| 2519 | }, |
| 2520 | { |
| 2521 | /* "hi6210sft" -> HiSilicon Kirin 620 */ |
| 2522 | .platform = "hi6210sft", |
| 2523 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2524 | .model = 620, |
| 2525 | }, |
| 2526 | { |
| 2527 | /* "hi3650" -> HiSilicon Kirin 950 */ |
| 2528 | .platform = "hi3650", |
| 2529 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2530 | .model = 950, |
| 2531 | }, |
| 2532 | { |
| 2533 | /* "hi3635" -> HiSilicon Kirin 930 */ |
| 2534 | .platform = "hi3635", |
| 2535 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2536 | .model = 930, |
| 2537 | }, |
| 2538 | { |
| 2539 | /* "hi3630" -> HiSilicon Kirin 920 */ |
| 2540 | .platform = "hi3630", |
| 2541 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2542 | .model = 920, |
| 2543 | }, |
| 2544 | { |
| 2545 | /* "k3v2oem1" -> HiSilicon K3V2 */ |
| 2546 | .platform = "k3v2oem1", |
| 2547 | .series = cpuinfo_arm_chipset_series_hisilicon_k3v, |
| 2548 | .model = 2, |
| 2549 | }, |
| 2550 | { |
| 2551 | /* "k3v200" -> HiSilicon K3V2 */ |
| 2552 | .platform = "k3v200", |
| 2553 | .series = cpuinfo_arm_chipset_series_hisilicon_k3v, |
| 2554 | .model = 2, |
| 2555 | }, |
| 2556 | { |
| 2557 | /* "montblanc" -> NovaThor U8500 */ |
| 2558 | .platform = "montblanc", |
| 2559 | .series = cpuinfo_arm_chipset_series_novathor_u, |
| 2560 | .model = 8500, |
| 2561 | }, |
| 2562 | { |
| 2563 | /* "song" -> Pinecone Surge S1 */ |
| 2564 | .platform = "song", |
| 2565 | .series = cpuinfo_arm_chipset_series_pinecone_surge_s, |
| 2566 | .model = 1, |
| 2567 | }, |
| 2568 | { |
| 2569 | /* "tegra132" -> nVidia Tegra T132 */ |
| 2570 | .platform = "tegra132", |
| 2571 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 2572 | .model = 132, |
| 2573 | }, |
| 2574 | { |
| 2575 | /* "tegra210_dragon" -> nVidia Tegra T210 */ |
| 2576 | .platform = "tegra210_dragon", |
| 2577 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 2578 | .model = 210, |
| 2579 | }, |
| 2580 | { |
| 2581 | /* "tegra4" -> nVidia Tegra T114 */ |
| 2582 | .platform = "tegra4", |
| 2583 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 2584 | .model = 114, |
| 2585 | }, |
| 2586 | { |
Marat Dukhan | 56b2403 | 2017-09-05 18:40:20 -0700 | [diff] [blame^] | 2587 | /* "s5pc110" -> Samsung Exynos 3110 */ |
| 2588 | .platform = "s5pc110", |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 2589 | .series = cpuinfo_arm_chipset_series_samsung_exynos, |
| 2590 | .model = 3110, |
| 2591 | }, |
| 2592 | }; |
| 2593 | |
| 2594 | /* |
| 2595 | * Decodes chipset name from ro.board.platform Android system property. |
| 2596 | * For some chipsets, the function relies frequency and on number of cores for chipset detection. |
| 2597 | * |
| 2598 | * @param[in] platform - ro.board.platform value. |
| 2599 | * @param cores - number of cores in the chipset. |
| 2600 | * @param max_cpu_freq_max - maximum of /sys/devices/system/cpu/cpu<number>/cpofreq/cpu_freq_max values. |
| 2601 | * |
| 2602 | * @returns Decoded chipset name. If chipset could not be decoded, the resulting structure would use `unknown` vendor |
| 2603 | * and series identifiers. |
| 2604 | */ |
| 2605 | struct cpuinfo_arm_chipset cpuinfo_arm_android_decode_chipset_from_ro_board_platform( |
| 2606 | const char platform[restrict static CPUINFO_BUILD_PROP_VALUE_MAX], |
| 2607 | uint32_t cores, uint32_t max_cpu_freq_max) |
| 2608 | { |
| 2609 | struct cpuinfo_arm_chipset chipset; |
| 2610 | const size_t platform_length = strnlen(platform, CPUINFO_BUILD_PROP_VALUE_MAX); |
| 2611 | const char* platform_end = platform + platform_length; |
| 2612 | |
| 2613 | /* Check Qualcomm MSM/APQ signature */ |
| 2614 | if (match_msm_apq(platform, platform_end, &chipset)) { |
| 2615 | cpuinfo_log_debug( |
| 2616 | "matched Qualcomm MSM/APQ signature in ro.board.platform string \"%.*s\"", |
| 2617 | (int) platform_length, platform); |
| 2618 | return chipset; |
| 2619 | } |
| 2620 | |
| 2621 | /* Check exynosXXXX (Samsung Exynos) signature */ |
| 2622 | if (match_exynos(platform, platform_end, &chipset)) { |
| 2623 | cpuinfo_log_debug( |
| 2624 | "matched exynosXXXX (Samsung Exynos) signature in ro.board.platform string \"%.*s\"", |
| 2625 | (int) platform_length, platform); |
| 2626 | return chipset; |
| 2627 | } |
| 2628 | |
| 2629 | /* Check MediaTek MT signature */ |
| 2630 | if (match_mt(platform, platform_end, true, &chipset)) { |
| 2631 | cpuinfo_log_debug( |
| 2632 | "matched MediaTek MT signature in ro.board.platform string \"%.*s\"", (int) platform_length, platform); |
| 2633 | return chipset; |
| 2634 | } |
| 2635 | |
| 2636 | /* Check Spreadtrum SC signature */ |
| 2637 | if (match_sc(platform, platform_end, &chipset)) { |
| 2638 | cpuinfo_log_debug( |
| 2639 | "matched Spreadtrum SC signature in ro.board.platform string \"%.*s\"", (int) platform_length, platform); |
| 2640 | return chipset; |
| 2641 | } |
| 2642 | |
| 2643 | /* Check Rockchip RK signature */ |
| 2644 | if (match_rk(platform, platform_end, &chipset)) { |
| 2645 | cpuinfo_log_debug( |
| 2646 | "matched Rockchip RK signature in ro.board.platform string \"%.*s\"", (int) platform_length, platform); |
| 2647 | return chipset; |
| 2648 | } |
| 2649 | |
| 2650 | /* Check Leadcore LCxxxx signature */ |
| 2651 | if (match_lc(platform, platform_end, &chipset)) { |
| 2652 | cpuinfo_log_debug( |
| 2653 | "matched Leadcore LC signature in ro.board.platform string \"%.*s\"", (int) platform_length, platform); |
| 2654 | return chipset; |
| 2655 | } |
| 2656 | |
| 2657 | /* Compare to tabulated ro.board.platform values for Huawei devices which don't report chipset elsewhere */ |
| 2658 | if (match_and_parse_huawei(platform, platform_end, &chipset)) { |
| 2659 | cpuinfo_log_debug( |
| 2660 | "found ro.board.platform string \"%.*s\" in Huawei chipset table", |
| 2661 | (int) platform_length, platform); |
| 2662 | return chipset; |
| 2663 | } |
| 2664 | |
| 2665 | /* |
| 2666 | * Compare to known ro.board.platform values for Broadcom devices and |
| 2667 | * detect chipset from frequency and number of cores |
| 2668 | */ |
| 2669 | if (match_and_parse_broadcom(platform, platform_end, cores, max_cpu_freq_max, &chipset)) { |
| 2670 | cpuinfo_log_debug( |
| 2671 | "found ro.board.platform string \"%.*s\" in Broadcom chipset table", |
| 2672 | (int) platform_length, platform); |
| 2673 | return chipset; |
| 2674 | } |
| 2675 | |
| 2676 | /* |
| 2677 | * Compare to ro.board.platform value ("omap4") for OMAP4xxx chipsets. |
| 2678 | * Upon successful match, detect OMAP4430 from frequency and number of cores. |
| 2679 | */ |
| 2680 | if (platform_length == 5 && cores == 2 && max_cpu_freq_max == 1008000 && memcmp(platform, "omap4", 5) == 0) { |
| 2681 | cpuinfo_log_debug( |
| 2682 | "matched Texas Instruments OMAP4 signature in ro.board.platform string \"%.*s\"", |
| 2683 | (int) platform_length, platform); |
| 2684 | |
| 2685 | return (struct cpuinfo_arm_chipset) { |
| 2686 | .vendor = cpuinfo_arm_chipset_vendor_texas_instruments, |
| 2687 | .series = cpuinfo_arm_chipset_series_texas_instruments_omap, |
| 2688 | .model = 4430, |
| 2689 | }; |
| 2690 | } |
| 2691 | |
| 2692 | /* |
| 2693 | * Compare to tabulated ro.board.platform values for Amlogic chipsets/devices which can't be otherwise detected. |
| 2694 | * The tabulated Amlogic ro.board.platform values have not more than 6 characters. |
| 2695 | */ |
| 2696 | if (platform_length <= 6) { |
| 2697 | for (size_t i = 0; i < CPUINFO_COUNT_OF(amlogic_map_entries); i++) { |
| 2698 | if (strncmp(amlogic_map_entries[i].ro_board_platform, platform, 6) == 0) { |
| 2699 | cpuinfo_log_debug( |
| 2700 | "found ro.board.platform string \"%.*s\" in Amlogic chipset table", |
| 2701 | (int) platform_length, platform); |
| 2702 | /* Create chipset name from entry */ |
| 2703 | return (struct cpuinfo_arm_chipset) { |
| 2704 | .vendor = cpuinfo_arm_chipset_vendor_amlogic, |
| 2705 | .series = (enum cpuinfo_arm_chipset_series) amlogic_map_entries[i].series, |
| 2706 | .model = amlogic_map_entries[i].model, |
| 2707 | .suffix = { |
| 2708 | [0] = amlogic_map_entries[i].suffix[0], |
| 2709 | [1] = amlogic_map_entries[i].suffix[1], |
| 2710 | [2] = amlogic_map_entries[i].suffix[2], |
| 2711 | }, |
| 2712 | }; |
| 2713 | } |
| 2714 | } |
| 2715 | } |
| 2716 | |
| 2717 | /* Compare to tabulated ro.board.platform values for popular chipsets/devices which can't be otherwise detected */ |
| 2718 | for (size_t i = 0; i < CPUINFO_COUNT_OF(special_platform_map_entries); i++) { |
| 2719 | if (strncmp(special_platform_map_entries[i].platform, platform, platform_length) == 0 && |
| 2720 | special_platform_map_entries[i].platform[platform_length] == 0) |
| 2721 | { |
| 2722 | /* Create chipset name from entry */ |
| 2723 | cpuinfo_log_debug( |
| 2724 | "found ro.board.platform string \"%.*s\" in special chipset table", (int) platform_length, platform); |
| 2725 | return (struct cpuinfo_arm_chipset) { |
| 2726 | .vendor = chipset_series_vendor[special_platform_map_entries[i].series], |
| 2727 | .series = (enum cpuinfo_arm_chipset_series) special_platform_map_entries[i].series, |
| 2728 | .model = special_platform_map_entries[i].model, |
| 2729 | .suffix = { |
| 2730 | [0] = special_platform_map_entries[i].suffix, |
| 2731 | }, |
| 2732 | }; |
| 2733 | } |
| 2734 | } |
| 2735 | |
| 2736 | /* None of the ro.board.platform signatures matched, indicate unknown chipset */ |
| 2737 | return (struct cpuinfo_arm_chipset) { |
| 2738 | .vendor = cpuinfo_arm_chipset_vendor_unknown, |
| 2739 | .series = cpuinfo_arm_chipset_series_unknown, |
| 2740 | }; |
| 2741 | } |
| 2742 | |
| 2743 | /* |
| 2744 | * Decodes chipset name from ro.mediatek.platform Android system property. |
| 2745 | * |
| 2746 | * @param[in] platform - ro.mediatek.platform value. |
| 2747 | * |
| 2748 | * @returns Decoded chipset name. If chipset could not be decoded, the resulting structure would use `unknown` vendor |
| 2749 | * and series identifiers. |
| 2750 | */ |
| 2751 | struct cpuinfo_arm_chipset cpuinfo_arm_android_decode_chipset_from_ro_mediatek_platform( |
| 2752 | const char platform[restrict static CPUINFO_BUILD_PROP_VALUE_MAX]) |
| 2753 | { |
| 2754 | struct cpuinfo_arm_chipset chipset; |
| 2755 | const char* platform_end = platform + strnlen(platform, CPUINFO_BUILD_PROP_VALUE_MAX);; |
| 2756 | |
| 2757 | /* Check MediaTek MT signature */ |
| 2758 | if (match_mt(platform, platform_end, false, &chipset)) { |
| 2759 | return chipset; |
| 2760 | } |
| 2761 | |
| 2762 | return (struct cpuinfo_arm_chipset) { |
| 2763 | .vendor = cpuinfo_arm_chipset_vendor_unknown, |
| 2764 | .series = cpuinfo_arm_chipset_series_unknown, |
| 2765 | }; |
| 2766 | } |
| 2767 | |
| 2768 | /* |
| 2769 | * Decodes chipset name from ro.chipname Android system property. |
| 2770 | * |
| 2771 | * @param[in] chipname - ro.chipname value. |
| 2772 | * |
| 2773 | * @returns Decoded chipset name. If chipset could not be decoded, the resulting structure would use `unknown` vendor |
| 2774 | * and series identifiers. |
| 2775 | */ |
| 2776 | struct cpuinfo_arm_chipset cpuinfo_arm_android_decode_chipset_from_ro_chipname( |
| 2777 | const char chipname[restrict static CPUINFO_BUILD_PROP_VALUE_MAX]) |
| 2778 | { |
| 2779 | struct cpuinfo_arm_chipset chipset; |
| 2780 | const size_t chipname_length = strnlen(chipname, CPUINFO_BUILD_PROP_VALUE_MAX); |
| 2781 | const char* chipname_end = chipname + chipname_length; |
| 2782 | |
| 2783 | /* Check Qualcomm MSM/APQ signatures */ |
| 2784 | if (match_msm_apq(chipname, chipname_end, &chipset)) { |
| 2785 | cpuinfo_log_debug( |
| 2786 | "matched Qualcomm MSM/APQ signature in ro.chipname string \"%.*s\"", |
| 2787 | (int) chipname_length, chipname); |
| 2788 | return chipset; |
| 2789 | } |
| 2790 | |
| 2791 | /* Check exynosXXXX (Samsung Exynos) signature */ |
| 2792 | if (match_exynos(chipname, chipname_end, &chipset)) { |
| 2793 | cpuinfo_log_debug( |
| 2794 | "matched exynosXXXX (Samsung Exynos) signature in ro.chipname string \"%.*s\"", |
| 2795 | (int) chipname_length, chipname); |
| 2796 | return chipset; |
| 2797 | } |
| 2798 | |
| 2799 | /* Check universalXXXX (Samsung Exynos) signature */ |
| 2800 | if (match_universal(chipname, chipname_end, &chipset)) { |
| 2801 | cpuinfo_log_debug( |
| 2802 | "matched UNIVERSAL (Samsung Exynos) signature in ro.chipname Hardware string \"%.*s\"", |
| 2803 | (int) chipname_length, chipname); |
| 2804 | return chipset; |
| 2805 | } |
| 2806 | |
| 2807 | /* Check MediaTek MT signature */ |
| 2808 | if (match_mt(chipname, chipname_end, true, &chipset)) { |
| 2809 | cpuinfo_log_debug( |
| 2810 | "matched MediaTek MT signature in ro.chipname string \"%.*s\"", |
| 2811 | (int) chipname_length, chipname); |
| 2812 | return chipset; |
| 2813 | } |
| 2814 | |
| 2815 | /* Check Spreadtrum SC signature */ |
| 2816 | if (match_sc(chipname, chipname_end, &chipset)) { |
| 2817 | cpuinfo_log_debug( |
| 2818 | "matched Spreadtrum SC signature in ro.chipname string \"%.*s\"", |
| 2819 | (int) chipname_length, chipname); |
| 2820 | return chipset; |
| 2821 | } |
| 2822 | |
| 2823 | /* Check Marvell PXA signature */ |
| 2824 | if (match_pxa(chipname, chipname_end, &chipset)) { |
| 2825 | cpuinfo_log_debug( |
| 2826 | "matched Marvell PXA signature in ro.chipname string \"%.*s\"", |
| 2827 | (int) chipname_length, chipname); |
| 2828 | return chipset; |
| 2829 | } |
| 2830 | |
| 2831 | /* Compare to ro.chipname value ("mp523x") for Renesas MP5232 which can't be otherwise detected */ |
| 2832 | if (chipname_length == 6 && memcmp(chipname, "mp523x", 6) == 0) { |
| 2833 | cpuinfo_log_debug( |
| 2834 | "matched Renesas MP5232 signature in ro.chipname string \"%.*s\"", |
| 2835 | (int) chipname_length, chipname); |
| 2836 | |
| 2837 | return (struct cpuinfo_arm_chipset) { |
| 2838 | .vendor = cpuinfo_arm_chipset_vendor_renesas, |
| 2839 | .series = cpuinfo_arm_chipset_series_renesas_mp, |
| 2840 | .model = 5232, |
| 2841 | }; |
| 2842 | } |
| 2843 | |
| 2844 | return (struct cpuinfo_arm_chipset) { |
| 2845 | .vendor = cpuinfo_arm_chipset_vendor_unknown, |
| 2846 | .series = cpuinfo_arm_chipset_series_unknown, |
| 2847 | }; |
| 2848 | } |
| 2849 | |
| 2850 | /* |
| 2851 | * Fix common bugs, typos, and renames in chipset name. |
| 2852 | * |
| 2853 | * @param[in,out] chipset - chipset name to fix. |
| 2854 | * @param cores - number of cores in the chipset. |
| 2855 | * @param max_cpu_freq_max - maximum of /sys/devices/system/cpu/cpu<number>/cpofreq/cpu_freq_max values. |
| 2856 | */ |
| 2857 | void cpuinfo_arm_fixup_chipset( |
| 2858 | struct cpuinfo_arm_chipset chipset[restrict static 1], uint32_t cores, uint32_t max_cpu_freq_max) |
| 2859 | { |
| 2860 | switch (chipset->series) { |
| 2861 | case cpuinfo_arm_chipset_series_qualcomm_msm: |
| 2862 | /* Check if there is suffix */ |
| 2863 | if (chipset->suffix[0] == 0) { |
| 2864 | /* No suffix, but the model may be misreported */ |
| 2865 | switch (chipset->model) { |
| 2866 | case 8216: |
| 2867 | /* MSM8216 was renamed to MSM8916 */ |
| 2868 | cpuinfo_log_info("reinterpreted MSM8216 chipset as MSM8916"); |
| 2869 | chipset->model = 8916; |
| 2870 | break; |
| 2871 | case 8916: |
| 2872 | /* Common bug: MSM8939 (Octa-core) reported as MSM8916 (Quad-core) */ |
| 2873 | switch (cores) { |
| 2874 | case 4: |
| 2875 | break; |
| 2876 | case 8: |
| 2877 | cpuinfo_log_info("reinterpreted MSM8916 chipset with 8 cores as MSM8939"); |
| 2878 | chipset->model = 8939; |
| 2879 | break; |
| 2880 | default: |
| 2881 | cpuinfo_log_warning("system reported invalid %"PRIu32"-core MSM%"PRIu32" chipset", |
| 2882 | cores, chipset->model); |
| 2883 | chipset->model = 0; |
| 2884 | } |
| 2885 | break; |
| 2886 | case 8937: |
| 2887 | /* Common bug: MSM8917 (Quad-core) reported as MSM8937 (Octa-core) */ |
| 2888 | switch (cores) { |
| 2889 | case 4: |
| 2890 | cpuinfo_log_info("reinterpreted MSM8937 chipset with 4 cores as MSM8917"); |
| 2891 | chipset->model = 8917; |
| 2892 | break; |
| 2893 | case 8: |
| 2894 | break; |
| 2895 | default: |
| 2896 | cpuinfo_log_warning("system reported invalid %"PRIu32"-core MSM%"PRIu32" chipset", |
| 2897 | cores, chipset->model); |
| 2898 | chipset->model = 0; |
| 2899 | } |
| 2900 | break; |
| 2901 | case 8960: |
| 2902 | /* Common bug: APQ8064 (Quad-core) reported as MSM8960 (Dual-core) */ |
| 2903 | switch (cores) { |
| 2904 | case 2: |
| 2905 | break; |
| 2906 | case 4: |
| 2907 | cpuinfo_log_info("reinterpreted MSM8960 chipset with 4 cores as APQ8064"); |
| 2908 | chipset->series = cpuinfo_arm_chipset_series_qualcomm_apq; |
| 2909 | chipset->model = 8064; |
| 2910 | break; |
| 2911 | default: |
| 2912 | cpuinfo_log_warning("system reported invalid %"PRIu32"-core MSM%"PRIu32" chipset", |
| 2913 | cores, chipset->model); |
| 2914 | chipset->model = 0; |
| 2915 | } |
| 2916 | break; |
| 2917 | case 8996: |
| 2918 | /* Common bug: MSM8994 (Octa-core) reported as MSM8996 (Quad-core) */ |
| 2919 | switch (cores) { |
| 2920 | case 4: |
| 2921 | break; |
| 2922 | case 8: |
| 2923 | cpuinfo_log_info("reinterpreted MSM8996 chipset with 8 cores as MSM8994"); |
| 2924 | chipset->model = 8994; |
| 2925 | break; |
| 2926 | default: |
| 2927 | cpuinfo_log_warning("system reported invalid %"PRIu32"-core MSM%"PRIu32" chipset", |
| 2928 | cores, chipset->model); |
| 2929 | chipset->model = 0; |
| 2930 | } |
| 2931 | break; |
| 2932 | case 8610: |
| 2933 | /* Common bug: MSM8212 (Quad-core) reported as MSM8610 (Dual-core) */ |
| 2934 | switch (cores) { |
| 2935 | case 2: |
| 2936 | break; |
| 2937 | case 4: |
| 2938 | cpuinfo_log_info("reinterpreted MSM8610 chipset with 4 cores as MSM8212"); |
| 2939 | chipset->model = 8212; |
| 2940 | break; |
| 2941 | default: |
| 2942 | cpuinfo_log_warning("system reported invalid %"PRIu32"-core MSM%"PRIu32" chipset", |
| 2943 | cores, chipset->model); |
| 2944 | chipset->model = 0; |
| 2945 | } |
| 2946 | break; |
| 2947 | } |
| 2948 | } else { |
| 2949 | /* Suffix may need correction */ |
| 2950 | const uint32_t suffix_word = load_u32le(chipset->suffix); |
| 2951 | if (suffix_word == UINT32_C(0x004D534D) /* "\0MSM" = reverse("MSM\0") */) { |
| 2952 | /* |
| 2953 | * Common bug: model name repeated twice, e.g. "MSM8916MSM8916" |
| 2954 | * In this case, model matching code parses the second "MSM" as a suffix |
| 2955 | */ |
| 2956 | chipset->suffix[0] = 0; |
| 2957 | chipset->suffix[1] = 0; |
| 2958 | chipset->suffix[2] = 0; |
| 2959 | } else { |
| 2960 | switch (chipset->model) { |
| 2961 | case 8976: |
| 2962 | /* MSM8976SG -> MSM8976PRO */ |
| 2963 | if (suffix_word == UINT32_C(0x00004753) /* "\0\0GS" = reverse("SG\0\0") */ ) { |
| 2964 | chipset->suffix[0] = 'P'; |
| 2965 | chipset->suffix[1] = 'R'; |
| 2966 | chipset->suffix[2] = 'O'; |
| 2967 | } |
| 2968 | break; |
| 2969 | case 8996: |
| 2970 | /* MSM8996PRO -> MSM8996PRO-AB or MSM8996PRO-AC */ |
| 2971 | if (suffix_word == UINT32_C(0x004F5250) /* "\0ORP" = reverse("PRO\0") */ ) { |
| 2972 | chipset->suffix[3] = '-'; |
| 2973 | chipset->suffix[4] = 'A'; |
| 2974 | chipset->suffix[5] = 'B' + (char) (max_cpu_freq_max >= 2188800); |
| 2975 | } |
| 2976 | break; |
| 2977 | } |
| 2978 | } |
| 2979 | } |
| 2980 | break; |
| 2981 | case cpuinfo_arm_chipset_series_qualcomm_apq: |
| 2982 | { |
| 2983 | /* Suffix may need correction */ |
| 2984 | const uint32_t expected_apq = load_u32le(chipset->suffix); |
| 2985 | if (expected_apq == UINT32_C(0x00515041) /* "\0QPA" = reverse("APQ\0") */) { |
| 2986 | /* |
| 2987 | * Common bug: model name repeated twice, e.g. "APQ8016APQ8016" |
| 2988 | * In this case, model matching code parses the second "APQ" as a suffix |
| 2989 | */ |
| 2990 | chipset->suffix[0] = 0; |
| 2991 | chipset->suffix[1] = 0; |
| 2992 | chipset->suffix[2] = 0; |
| 2993 | } |
| 2994 | break; |
| 2995 | } |
| 2996 | case cpuinfo_arm_chipset_series_samsung_exynos: |
| 2997 | if (chipset->model == 7580) { |
| 2998 | /* Common bug: Exynos 7578 (Quad-core) reported as Exynos 7580 (Octa-core) */ |
| 2999 | switch (cores) { |
| 3000 | case 4: |
| 3001 | cpuinfo_log_info("reinterpreted Exynos 7580 chipset with 4 cores as Exynos 7578"); |
| 3002 | chipset->model = 7578; |
| 3003 | break; |
| 3004 | case 8: |
| 3005 | break; |
| 3006 | default: |
| 3007 | cpuinfo_log_warning("system reported invalid %"PRIu32"-core Exynos 7580 chipset", cores); |
| 3008 | chipset->model = 0; |
| 3009 | } |
| 3010 | } |
| 3011 | break; |
| 3012 | case cpuinfo_arm_chipset_series_mediatek_mt: |
| 3013 | if (chipset->model == 6752) { |
| 3014 | /* Common bug: MT6732 (Quad-core) reported as MT6752 (Octa-core) */ |
| 3015 | switch (cores) { |
| 3016 | case 4: |
| 3017 | cpuinfo_log_info("reinterpreted MT6752 chipset with 4 cores as MT6732"); |
| 3018 | chipset->model = 6732; |
| 3019 | break; |
| 3020 | case 8: |
| 3021 | break; |
| 3022 | default: |
| 3023 | cpuinfo_log_warning("system reported invalid %"PRIu32"-core MT6752 chipset", cores); |
| 3024 | chipset->model = 0; |
| 3025 | } |
| 3026 | } |
| 3027 | if (chipset->suffix[0] == 'T') { |
| 3028 | /* Normalization: "TURBO" and "TRUBO" (apparently a typo) -> "T" */ |
| 3029 | const uint32_t suffix_word = load_u32le(chipset->suffix + 1); |
| 3030 | switch (suffix_word) { |
| 3031 | case UINT32_C(0x4F425255): /* "OBRU" = reverse("URBO") */ |
| 3032 | case UINT32_C(0x4F425552): /* "OBUR" = reverse("RUBO") */ |
| 3033 | if (chipset->suffix[5] == 0) { |
| 3034 | chipset->suffix[1] = 0; |
| 3035 | chipset->suffix[2] = 0; |
| 3036 | chipset->suffix[3] = 0; |
| 3037 | chipset->suffix[4] = 0; |
| 3038 | } |
| 3039 | break; |
| 3040 | } |
| 3041 | } |
| 3042 | break; |
| 3043 | default: |
| 3044 | break; |
| 3045 | } |
| 3046 | } |
| 3047 | |
| 3048 | /* Map from ARM chipset vendor ID to its string representation */ |
| 3049 | static const char* chipset_vendor_string[cpuinfo_arm_chipset_vendor_max] = { |
| 3050 | [cpuinfo_arm_chipset_vendor_unknown] = "Unknown", |
| 3051 | [cpuinfo_arm_chipset_vendor_qualcomm] = "Qualcomm", |
| 3052 | [cpuinfo_arm_chipset_vendor_mediatek] = "MediaTek", |
| 3053 | [cpuinfo_arm_chipset_vendor_samsung] = "Samsung", |
| 3054 | [cpuinfo_arm_chipset_vendor_hisilicon] = "HiSilicon", |
| 3055 | [cpuinfo_arm_chipset_vendor_actions] = "Actions", |
| 3056 | [cpuinfo_arm_chipset_vendor_allwinner] = "Allwinner", |
| 3057 | [cpuinfo_arm_chipset_vendor_amlogic] = "Amlogic", |
| 3058 | [cpuinfo_arm_chipset_vendor_broadcom] = "Broadcom", |
| 3059 | [cpuinfo_arm_chipset_vendor_lg] = "LG", |
| 3060 | [cpuinfo_arm_chipset_vendor_leadcore] = "Leadcore", |
| 3061 | [cpuinfo_arm_chipset_vendor_marvell] = "Marvell", |
| 3062 | [cpuinfo_arm_chipset_vendor_mstar] = "MStar", |
| 3063 | [cpuinfo_arm_chipset_vendor_novathor] = "NovaThor", |
| 3064 | [cpuinfo_arm_chipset_vendor_nvidia] = "nVidia", |
| 3065 | [cpuinfo_arm_chipset_vendor_pinecone] = "Pinecone", |
| 3066 | [cpuinfo_arm_chipset_vendor_renesas] = "Renesas", |
| 3067 | [cpuinfo_arm_chipset_vendor_rockchip] = "Rockchip", |
| 3068 | [cpuinfo_arm_chipset_vendor_spreadtrum] = "Spreadtrum", |
| 3069 | [cpuinfo_arm_chipset_vendor_telechips] = "Telechips", |
| 3070 | [cpuinfo_arm_chipset_vendor_texas_instruments] = "Texas Instruments", |
| 3071 | [cpuinfo_arm_chipset_vendor_wondermedia] = "WonderMedia", |
| 3072 | }; |
| 3073 | |
| 3074 | /* Map from ARM chipset series ID to its string representation */ |
| 3075 | static const char* chipset_series_string[cpuinfo_arm_chipset_series_max] = { |
| 3076 | [cpuinfo_arm_chipset_series_unknown] = NULL, |
| 3077 | [cpuinfo_arm_chipset_series_qualcomm_qsd] = "QSD", |
| 3078 | [cpuinfo_arm_chipset_series_qualcomm_msm] = "MSM", |
| 3079 | [cpuinfo_arm_chipset_series_qualcomm_apq] = "APQ", |
| 3080 | [cpuinfo_arm_chipset_series_qualcomm_snapdragon] = "Snapdragon ", |
| 3081 | [cpuinfo_arm_chipset_series_mediatek_mt] = "MT", |
| 3082 | [cpuinfo_arm_chipset_series_samsung_exynos] = "Exynos ", |
| 3083 | [cpuinfo_arm_chipset_series_hisilicon_k3v] = "K3V", |
| 3084 | [cpuinfo_arm_chipset_series_hisilicon_hi] = "Hi", |
| 3085 | [cpuinfo_arm_chipset_series_hisilicon_kirin] = "Kirin ", |
| 3086 | [cpuinfo_arm_chipset_series_actions_atm] = "ATM", |
| 3087 | [cpuinfo_arm_chipset_series_allwinner_a] = "A", |
| 3088 | [cpuinfo_arm_chipset_series_amlogic_aml] = "AML", |
| 3089 | [cpuinfo_arm_chipset_series_amlogic_s] = "S", |
| 3090 | [cpuinfo_arm_chipset_series_broadcom_bcm] = "BCM", |
| 3091 | [cpuinfo_arm_chipset_series_lg_nuclun] = "Nuclun ", |
| 3092 | [cpuinfo_arm_chipset_series_leadcore_lc] = "LC", |
| 3093 | [cpuinfo_arm_chipset_series_marvell_pxa] = "PXA", |
| 3094 | [cpuinfo_arm_chipset_series_mstar_6a] = "6A", |
| 3095 | [cpuinfo_arm_chipset_series_novathor_u] = "U", |
| 3096 | [cpuinfo_arm_chipset_series_nvidia_tegra_t] = "Tegra T", |
| 3097 | [cpuinfo_arm_chipset_series_nvidia_tegra_ap] = "Tegra AP", |
| 3098 | [cpuinfo_arm_chipset_series_nvidia_tegra_sl] = "Tegra SL", |
| 3099 | [cpuinfo_arm_chipset_series_pinecone_surge_s] = "Surge S", |
| 3100 | [cpuinfo_arm_chipset_series_renesas_mp] = "MP", |
| 3101 | [cpuinfo_arm_chipset_series_rockchip_rk] = "RK", |
| 3102 | [cpuinfo_arm_chipset_series_spreadtrum_sc] = "SC", |
| 3103 | [cpuinfo_arm_chipset_series_telechips_tcc] = "TCC", |
| 3104 | [cpuinfo_arm_chipset_series_texas_instruments_omap] = "OMAP", |
| 3105 | [cpuinfo_arm_chipset_series_wondermedia_wm] = "WM", |
| 3106 | }; |
| 3107 | |
| 3108 | /* Convert chipset name represented by cpuinfo_arm_chipset structure to a string representation */ |
| 3109 | void cpuinfo_arm_chipset_to_string( |
| 3110 | const struct cpuinfo_arm_chipset chipset[restrict static 1], |
| 3111 | char name[restrict static CPUINFO_ARM_CHIPSET_NAME_MAX]) |
| 3112 | { |
| 3113 | enum cpuinfo_arm_chipset_vendor vendor = chipset->vendor; |
| 3114 | if (vendor >= cpuinfo_arm_chipset_vendor_max) { |
| 3115 | vendor = cpuinfo_arm_chipset_vendor_unknown; |
| 3116 | } |
| 3117 | enum cpuinfo_arm_chipset_series series = chipset->series; |
| 3118 | if (series >= cpuinfo_arm_chipset_series_max) { |
| 3119 | series = cpuinfo_arm_chipset_series_unknown; |
| 3120 | } |
| 3121 | const char* vendor_string = chipset_vendor_string[vendor]; |
| 3122 | const char* series_string = chipset_series_string[series]; |
| 3123 | const uint32_t model = chipset->model; |
| 3124 | if (model == 0) { |
| 3125 | if (series == cpuinfo_arm_chipset_series_unknown) { |
| 3126 | strncpy(name, vendor_string, CPUINFO_ARM_CHIPSET_NAME_MAX); |
| 3127 | } else { |
| 3128 | snprintf(name, CPUINFO_ARM_CHIPSET_NAME_MAX, |
| 3129 | "%s %s", vendor_string, series_string); |
| 3130 | } |
| 3131 | } else { |
| 3132 | const size_t suffix_length = strnlen(chipset->suffix, CPUINFO_ARM_CHIPSET_SUFFIX_MAX); |
| 3133 | snprintf(name, CPUINFO_ARM_CHIPSET_NAME_MAX, |
| 3134 | "%s %s%"PRIu32"%.*s", vendor_string, series_string, model, (int) suffix_length, chipset->suffix); |
| 3135 | } |
| 3136 | } |
| 3137 | |
| 3138 | static inline struct cpuinfo_arm_chipset disambiguate_qualcomm_chipset( |
| 3139 | const struct cpuinfo_arm_chipset proc_cpuinfo_hardware_chipset[restrict static 1], |
| 3140 | const struct cpuinfo_arm_chipset ro_product_board_chipset[restrict static 1], |
| 3141 | const struct cpuinfo_arm_chipset ro_board_platform_chipset[restrict static 1], |
| 3142 | const struct cpuinfo_arm_chipset ro_chipname_chipset[restrict static 1]) |
| 3143 | { |
| 3144 | if (ro_chipname_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3145 | return *ro_chipname_chipset; |
| 3146 | } |
| 3147 | if (proc_cpuinfo_hardware_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3148 | return *proc_cpuinfo_hardware_chipset; |
| 3149 | } |
| 3150 | if (ro_product_board_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3151 | return *ro_product_board_chipset; |
| 3152 | } |
| 3153 | return *ro_board_platform_chipset; |
| 3154 | } |
| 3155 | |
| 3156 | static inline struct cpuinfo_arm_chipset disambiguate_mediatek_chipset( |
| 3157 | const struct cpuinfo_arm_chipset proc_cpuinfo_hardware_chipset[restrict static 1], |
| 3158 | const struct cpuinfo_arm_chipset ro_product_board_chipset[restrict static 1], |
| 3159 | const struct cpuinfo_arm_chipset ro_board_platform_chipset[restrict static 1], |
| 3160 | const struct cpuinfo_arm_chipset ro_mediatek_platform_chipset[restrict static 1], |
| 3161 | const struct cpuinfo_arm_chipset ro_chipname_chipset[restrict static 1]) |
| 3162 | { |
| 3163 | if (ro_chipname_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3164 | return *ro_chipname_chipset; |
| 3165 | } |
| 3166 | if (proc_cpuinfo_hardware_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3167 | return *proc_cpuinfo_hardware_chipset; |
| 3168 | } |
| 3169 | if (ro_product_board_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3170 | return *ro_product_board_chipset; |
| 3171 | } |
| 3172 | if (ro_board_platform_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3173 | return *ro_board_platform_chipset; |
| 3174 | } |
| 3175 | return *ro_mediatek_platform_chipset; |
| 3176 | } |
| 3177 | |
| 3178 | static inline struct cpuinfo_arm_chipset disambiguate_hisilicon_chipset( |
| 3179 | const struct cpuinfo_arm_chipset proc_cpuinfo_hardware_chipset[restrict static 1], |
| 3180 | const struct cpuinfo_arm_chipset ro_product_board_chipset[restrict static 1], |
| 3181 | const struct cpuinfo_arm_chipset ro_board_platform_chipset[restrict static 1]) |
| 3182 | { |
| 3183 | if (proc_cpuinfo_hardware_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3184 | return *proc_cpuinfo_hardware_chipset; |
| 3185 | } |
| 3186 | if (ro_product_board_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3187 | return *ro_product_board_chipset; |
| 3188 | } |
| 3189 | return *ro_board_platform_chipset; |
| 3190 | } |
| 3191 | |
| 3192 | static inline struct cpuinfo_arm_chipset disambiguate_amlogic_chipset( |
| 3193 | const struct cpuinfo_arm_chipset proc_cpuinfo_hardware_chipset[restrict static 1], |
| 3194 | const struct cpuinfo_arm_chipset ro_board_platform_chipset[restrict static 1]) |
| 3195 | { |
| 3196 | if (proc_cpuinfo_hardware_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3197 | return *proc_cpuinfo_hardware_chipset; |
| 3198 | } |
| 3199 | return *ro_board_platform_chipset; |
| 3200 | } |
| 3201 | |
| 3202 | static inline struct cpuinfo_arm_chipset disambiguate_marvell_chipset( |
| 3203 | const struct cpuinfo_arm_chipset proc_cpuinfo_hardware_chipset[restrict static 1], |
| 3204 | const struct cpuinfo_arm_chipset ro_product_board_chipset[restrict static 1], |
| 3205 | const struct cpuinfo_arm_chipset ro_chipname_chipset[restrict static 1]) |
| 3206 | { |
| 3207 | if (ro_chipname_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3208 | return *ro_chipname_chipset; |
| 3209 | } |
| 3210 | if (ro_product_board_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3211 | return *ro_product_board_chipset; |
| 3212 | } |
| 3213 | return *proc_cpuinfo_hardware_chipset; |
| 3214 | } |
| 3215 | |
| 3216 | static inline struct cpuinfo_arm_chipset disambiguate_rockchip_chipset( |
| 3217 | const struct cpuinfo_arm_chipset proc_cpuinfo_hardware_chipset[restrict static 1], |
| 3218 | const struct cpuinfo_arm_chipset ro_product_board_chipset[restrict static 1], |
| 3219 | const struct cpuinfo_arm_chipset ro_board_platform_chipset[restrict static 1]) |
| 3220 | { |
| 3221 | if (ro_product_board_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3222 | return *ro_product_board_chipset; |
| 3223 | } |
| 3224 | if (proc_cpuinfo_hardware_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3225 | return *proc_cpuinfo_hardware_chipset; |
| 3226 | } |
| 3227 | return *ro_board_platform_chipset; |
| 3228 | } |
| 3229 | |
| 3230 | static inline struct cpuinfo_arm_chipset disambiguate_spreadtrum_chipset( |
| 3231 | const struct cpuinfo_arm_chipset proc_cpuinfo_hardware_chipset[restrict static 1], |
| 3232 | const struct cpuinfo_arm_chipset ro_product_board_chipset[restrict static 1], |
| 3233 | const struct cpuinfo_arm_chipset ro_board_platform_chipset[restrict static 1], |
| 3234 | const struct cpuinfo_arm_chipset ro_chipname_chipset[restrict static 1]) |
| 3235 | { |
| 3236 | if (ro_chipname_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3237 | return *ro_chipname_chipset; |
| 3238 | } |
| 3239 | if (ro_product_board_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3240 | return *ro_product_board_chipset; |
| 3241 | } |
| 3242 | if (proc_cpuinfo_hardware_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3243 | return *proc_cpuinfo_hardware_chipset; |
| 3244 | } |
| 3245 | return *ro_board_platform_chipset; |
| 3246 | } |
| 3247 | |
| 3248 | /* |
| 3249 | * Decodes chipset name from Android system properties: |
| 3250 | * - /proc/cpuinfo Hardware string |
| 3251 | * - ro.product.board |
| 3252 | * - ro.board.platform |
| 3253 | * - ro.mediatek.platform |
| 3254 | * - ro.chipname |
| 3255 | * For some chipsets, the function relies frequency and on number of cores for chipset detection. |
| 3256 | * |
| 3257 | * @param[in] properties - structure with the Android system properties described above. |
| 3258 | * @param cores - number of cores in the chipset. |
| 3259 | * @param max_cpu_freq_max - maximum of /sys/devices/system/cpu/cpu<number>/cpofreq/cpu_freq_max values. |
| 3260 | * |
| 3261 | * @returns Decoded chipset name. If chipset could not be decoded, the resulting structure would use `unknown` vendor |
| 3262 | * and series identifiers. |
| 3263 | */ |
| 3264 | struct cpuinfo_arm_chipset cpuinfo_arm_android_decode_chipset( |
| 3265 | const struct cpuinfo_android_properties properties[restrict static 1], |
| 3266 | uint32_t cores, |
| 3267 | uint32_t max_cpu_freq_max) |
| 3268 | { |
| 3269 | struct cpuinfo_arm_chipset chipset = { |
| 3270 | .vendor = cpuinfo_arm_chipset_vendor_unknown, |
| 3271 | .series = cpuinfo_arm_chipset_series_unknown, |
| 3272 | }; |
| 3273 | |
| 3274 | const bool tegra_platform = is_tegra( |
| 3275 | properties->ro_board_platform, |
| 3276 | properties->ro_board_platform + strnlen(properties->ro_board_platform, CPUINFO_BUILD_PROP_VALUE_MAX)); |
| 3277 | |
| 3278 | struct cpuinfo_arm_chipset chipsets[cpuinfo_android_chipset_property_max] = { |
| 3279 | [cpuinfo_android_chipset_property_proc_cpuinfo_hardware] = |
| 3280 | cpuinfo_arm_android_decode_chipset_from_proc_cpuinfo_hardware( |
| 3281 | properties->proc_cpuinfo_hardware, cores, max_cpu_freq_max, tegra_platform), |
| 3282 | [cpuinfo_android_chipset_property_ro_product_board] = |
| 3283 | cpuinfo_arm_android_decode_chipset_from_ro_product_board( |
| 3284 | properties->ro_product_board, cores, max_cpu_freq_max), |
| 3285 | [cpuinfo_android_chipset_property_ro_board_platform] = |
| 3286 | cpuinfo_arm_android_decode_chipset_from_ro_board_platform( |
| 3287 | properties->ro_board_platform, cores, max_cpu_freq_max), |
| 3288 | [cpuinfo_android_chipset_property_ro_mediatek_platform] = |
| 3289 | cpuinfo_arm_android_decode_chipset_from_ro_mediatek_platform(properties->ro_mediatek_platform), |
| 3290 | [cpuinfo_android_chipset_property_ro_chipname] = |
| 3291 | cpuinfo_arm_android_decode_chipset_from_ro_chipname(properties->ro_chipname), |
| 3292 | }; |
| 3293 | enum cpuinfo_arm_chipset_vendor vendor = cpuinfo_arm_chipset_vendor_unknown; |
| 3294 | for (size_t i = 0; i < cpuinfo_android_chipset_property_max; i++) { |
| 3295 | const enum cpuinfo_arm_chipset_vendor decoded_vendor = chipsets[i].vendor; |
| 3296 | if (decoded_vendor != cpuinfo_arm_chipset_vendor_unknown) { |
| 3297 | if (vendor == cpuinfo_arm_chipset_vendor_unknown) { |
| 3298 | vendor = decoded_vendor; |
| 3299 | } else if (vendor != decoded_vendor) { |
| 3300 | /* Parsing different system properties produces different chipset vendors. This situation is rare. */ |
| 3301 | cpuinfo_log_error( |
| 3302 | "chipset detection failed: different chipset vendors reported in different system properties"); |
| 3303 | goto finish; |
| 3304 | } |
| 3305 | } |
| 3306 | } |
| 3307 | if (vendor == cpuinfo_arm_chipset_vendor_unknown) { |
| 3308 | cpuinfo_log_warning( |
| 3309 | "chipset detection failed: none of the system properties matched known signatures"); |
| 3310 | goto finish; |
| 3311 | } |
| 3312 | |
| 3313 | /* Fix common bugs in reported chipsets */ |
| 3314 | for (size_t i = 0; i < cpuinfo_android_chipset_property_max; i++) { |
| 3315 | cpuinfo_arm_fixup_chipset(&chipsets[i], cores, max_cpu_freq_max); |
| 3316 | } |
| 3317 | |
| 3318 | /* |
| 3319 | * Propagate suffixes: consider all pairs of chipsets, if both chipsets in the pair are from the same series, |
| 3320 | * and one's suffix is a prefix of another's chipset suffix, use the longest suffix. |
| 3321 | */ |
| 3322 | for (size_t i = 0; i < cpuinfo_android_chipset_property_max; i++) { |
| 3323 | const size_t chipset_i_suffix_length = strnlen(chipsets[i].suffix, CPUINFO_ARM_CHIPSET_SUFFIX_MAX); |
| 3324 | for (size_t j = 0; j < i; j++) { |
| 3325 | if (chipsets[i].series == chipsets[j].series) { |
| 3326 | const size_t chipset_j_suffix_length = strnlen(chipsets[j].suffix, CPUINFO_ARM_CHIPSET_SUFFIX_MAX); |
| 3327 | if (chipset_i_suffix_length != chipset_j_suffix_length) { |
| 3328 | const size_t common_prefix_length = (chipset_i_suffix_length < chipset_j_suffix_length) ? |
| 3329 | chipset_i_suffix_length : chipset_j_suffix_length; |
| 3330 | if (common_prefix_length == 0 || |
| 3331 | memcmp(chipsets[i].suffix, chipsets[j].suffix, common_prefix_length) == 0) |
| 3332 | { |
| 3333 | if (chipset_i_suffix_length > chipset_j_suffix_length) { |
| 3334 | memcpy(chipsets[j].suffix, chipsets[i].suffix, chipset_i_suffix_length); |
| 3335 | } else { |
| 3336 | memcpy(chipsets[i].suffix, chipsets[j].suffix, chipset_j_suffix_length); |
| 3337 | } |
| 3338 | } |
| 3339 | } |
| 3340 | } |
| 3341 | } |
| 3342 | } |
| 3343 | |
| 3344 | for (size_t i = 0; i < cpuinfo_android_chipset_property_max; i++) { |
| 3345 | if (chipsets[i].series != cpuinfo_arm_chipset_series_unknown) { |
| 3346 | if (chipset.series == cpuinfo_arm_chipset_series_unknown) { |
| 3347 | chipset = chipsets[i]; |
| 3348 | } else if (chipsets[i].series != chipset.series || chipsets[i].model != chipset.model || |
| 3349 | strncmp(chipsets[i].suffix, chipset.suffix, CPUINFO_ARM_CHIPSET_SUFFIX_MAX) != 0) |
| 3350 | { |
| 3351 | cpuinfo_log_info( |
| 3352 | "different chipsets reported in different system properties; " |
| 3353 | "vendor-specific disambiguation heuristic would be used"); |
| 3354 | switch (vendor) { |
| 3355 | case cpuinfo_arm_chipset_vendor_qualcomm: |
| 3356 | return disambiguate_qualcomm_chipset( |
| 3357 | &chipsets[cpuinfo_android_chipset_property_proc_cpuinfo_hardware], |
| 3358 | &chipsets[cpuinfo_android_chipset_property_ro_product_board], |
| 3359 | &chipsets[cpuinfo_android_chipset_property_ro_board_platform], |
| 3360 | &chipsets[cpuinfo_android_chipset_property_ro_chipname]); |
| 3361 | case cpuinfo_arm_chipset_vendor_mediatek: |
| 3362 | return disambiguate_mediatek_chipset( |
| 3363 | &chipsets[cpuinfo_android_chipset_property_proc_cpuinfo_hardware], |
| 3364 | &chipsets[cpuinfo_android_chipset_property_ro_product_board], |
| 3365 | &chipsets[cpuinfo_android_chipset_property_ro_board_platform], |
| 3366 | &chipsets[cpuinfo_android_chipset_property_ro_mediatek_platform], |
| 3367 | &chipsets[cpuinfo_android_chipset_property_ro_chipname]); |
| 3368 | case cpuinfo_arm_chipset_vendor_hisilicon: |
| 3369 | return disambiguate_hisilicon_chipset( |
| 3370 | &chipsets[cpuinfo_android_chipset_property_proc_cpuinfo_hardware], |
| 3371 | &chipsets[cpuinfo_android_chipset_property_ro_product_board], |
| 3372 | &chipsets[cpuinfo_android_chipset_property_ro_board_platform]); |
| 3373 | case cpuinfo_arm_chipset_vendor_amlogic: |
| 3374 | return disambiguate_amlogic_chipset( |
| 3375 | &chipsets[cpuinfo_android_chipset_property_proc_cpuinfo_hardware], |
| 3376 | &chipsets[cpuinfo_android_chipset_property_ro_board_platform]); |
| 3377 | case cpuinfo_arm_chipset_vendor_marvell: |
| 3378 | return disambiguate_marvell_chipset( |
| 3379 | &chipsets[cpuinfo_android_chipset_property_proc_cpuinfo_hardware], |
| 3380 | &chipsets[cpuinfo_android_chipset_property_ro_product_board], |
| 3381 | &chipsets[cpuinfo_android_chipset_property_ro_chipname]); |
| 3382 | case cpuinfo_arm_chipset_vendor_rockchip: |
| 3383 | return disambiguate_rockchip_chipset( |
| 3384 | &chipsets[cpuinfo_android_chipset_property_proc_cpuinfo_hardware], |
| 3385 | &chipsets[cpuinfo_android_chipset_property_ro_product_board], |
| 3386 | &chipsets[cpuinfo_android_chipset_property_ro_board_platform]); |
| 3387 | case cpuinfo_arm_chipset_vendor_spreadtrum: |
| 3388 | return disambiguate_spreadtrum_chipset( |
| 3389 | &chipsets[cpuinfo_android_chipset_property_proc_cpuinfo_hardware], |
| 3390 | &chipsets[cpuinfo_android_chipset_property_ro_product_board], |
| 3391 | &chipsets[cpuinfo_android_chipset_property_ro_board_platform], |
| 3392 | &chipsets[cpuinfo_android_chipset_property_ro_chipname]); |
| 3393 | default: |
| 3394 | cpuinfo_log_error( |
| 3395 | "chipset detection failed: " |
| 3396 | "could not disambiguate different chipsets reported in different system properties"); |
| 3397 | /* chipset variable contains valid, but inconsistent chipset information, overwrite it */ |
| 3398 | chipset = (struct cpuinfo_arm_chipset) { |
| 3399 | .vendor = cpuinfo_arm_chipset_vendor_unknown, |
| 3400 | .series = cpuinfo_arm_chipset_series_unknown, |
| 3401 | }; |
| 3402 | goto finish; |
| 3403 | } |
| 3404 | } |
| 3405 | } |
| 3406 | } |
| 3407 | |
| 3408 | finish: |
| 3409 | return chipset; |
| 3410 | } |