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 | |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame^] | 2219 | #ifdef __ANDROID__ |
| 2220 | static const struct special_map_entry special_board_map_entries[] = { |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 2221 | { |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame^] | 2222 | /* "hi6250" -> HiSilicon Kirin 650 */ |
| 2223 | .platform = "hi6250", |
| 2224 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2225 | .model = 650, |
| 2226 | }, |
| 2227 | { |
| 2228 | /* "hi6210sft" -> HiSilicon Kirin 620 */ |
| 2229 | .platform = "hi6210sft", |
| 2230 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2231 | .model = 620, |
| 2232 | }, |
| 2233 | { |
| 2234 | /* "hi3650" -> HiSilicon Kirin 950 */ |
| 2235 | .platform = "hi3650", |
| 2236 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2237 | .model = 950, |
| 2238 | }, |
| 2239 | { |
| 2240 | /* "hi3635" -> HiSilicon Kirin 930 */ |
| 2241 | .platform = "hi3635", |
| 2242 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2243 | .model = 930, |
| 2244 | }, |
| 2245 | { |
| 2246 | /* "hi3630" -> HiSilicon Kirin 920 */ |
| 2247 | .platform = "hi3630", |
| 2248 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2249 | .model = 920, |
| 2250 | }, |
| 2251 | { |
| 2252 | /* "mp523x" -> Renesas MP5232 */ |
| 2253 | .platform = "mp523x", |
| 2254 | .series = cpuinfo_arm_chipset_series_renesas_mp, |
| 2255 | .model = 5232, |
| 2256 | }, |
| 2257 | { |
| 2258 | /* "piranha" -> Texas Instruments OMAP4430 */ |
| 2259 | .platform = "piranha", |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 2260 | .series = cpuinfo_arm_chipset_series_texas_instruments_omap, |
| 2261 | .model = 4430, |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame^] | 2262 | }, |
| 2263 | { |
| 2264 | /* "BEETHOVEN" (Huawei MadiaPad M3) -> HiSilicon Kirin 950 */ |
| 2265 | .platform = "BEETHOVEN", |
| 2266 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2267 | .model = 950, |
| 2268 | }, |
| 2269 | { |
| 2270 | /* "hws7701u" (Huawei MediaPad 7 Youth) -> Rockchip RK3168 */ |
| 2271 | .platform = "hws7701u", |
| 2272 | .series = cpuinfo_arm_chipset_series_rockchip_rk, |
| 2273 | .model = 3168, |
| 2274 | }, |
| 2275 | { |
| 2276 | /* "g2mv" (LG G2 mini LTE) -> nVidia Tegra SL460N */ |
| 2277 | .platform = "g2mv", |
| 2278 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_sl, |
| 2279 | .model = 460, |
| 2280 | .suffix = 'N', |
| 2281 | }, |
| 2282 | { |
| 2283 | /* "K00F" (Asus MeMO Pad 10) -> Rockchip RK3188 */ |
| 2284 | .platform = "K00F", |
| 2285 | .series = cpuinfo_arm_chipset_series_rockchip_rk, |
| 2286 | .model = 3188, |
| 2287 | }, |
| 2288 | { |
| 2289 | /* "T7H" (HP Slate 7) -> Rockchip RK3066 */ |
| 2290 | .platform = "T7H", |
| 2291 | .series = cpuinfo_arm_chipset_series_rockchip_rk, |
| 2292 | .model = 3066, |
| 2293 | }, |
| 2294 | { |
| 2295 | /* "tuna" (Samsung Galaxy Nexus) -> Texas Instruments OMAP4460 */ |
| 2296 | .platform = "tuna", |
| 2297 | .series = cpuinfo_arm_chipset_series_texas_instruments_omap, |
| 2298 | .model = 4460, |
| 2299 | }, |
| 2300 | { |
| 2301 | /* "grouper" (Asus Nexus 7 2012) -> nVidia Tegra T30L */ |
| 2302 | .platform = "grouper", |
| 2303 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 2304 | .model = 30, |
| 2305 | .suffix = 'L', |
| 2306 | }, |
| 2307 | { |
| 2308 | /* "flounder" (HTC Nexus 9) -> nVidia Tegra T132 */ |
| 2309 | .platform = "flounder", |
| 2310 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 2311 | .model = 132, |
| 2312 | }, |
| 2313 | { |
| 2314 | /* "dragon" (Google Pixel C) -> nVidia Tegra T210 */ |
| 2315 | .platform = "dragon", |
| 2316 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 2317 | .model = 210, |
| 2318 | }, |
| 2319 | { |
| 2320 | /* "sailfish" (Google Pixel) -> Qualcomm MSM8996PRO */ |
| 2321 | .platform = "sailfish", |
| 2322 | .series = cpuinfo_arm_chipset_series_qualcomm_msm, |
| 2323 | .model = 8996, |
| 2324 | .suffix = 'P', |
| 2325 | }, |
| 2326 | { |
| 2327 | /* "marlin" (Google Pixel XL) -> Qualcomm MSM8996PRO */ |
| 2328 | .platform = "marlin", |
| 2329 | .series = cpuinfo_arm_chipset_series_qualcomm_msm, |
| 2330 | .model = 8996, |
| 2331 | .suffix = 'P', |
| 2332 | }, |
| 2333 | }; |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 2334 | |
| 2335 | /* |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame^] | 2336 | * Decodes chipset name from ro.product.board Android system property. |
| 2337 | * For some chipsets, the function relies frequency and on number of cores for chipset detection. |
| 2338 | * |
| 2339 | * @param[in] platform - ro.product.board value. |
| 2340 | * @param cores - number of cores in the chipset. |
| 2341 | * @param max_cpu_freq_max - maximum of /sys/devices/system/cpu/cpu<number>/cpofreq/cpu_freq_max values. |
| 2342 | * |
| 2343 | * @returns Decoded chipset name. If chipset could not be decoded, the resulting structure would use `unknown` vendor |
| 2344 | * and series identifiers. |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 2345 | */ |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame^] | 2346 | struct cpuinfo_arm_chipset cpuinfo_arm_android_decode_chipset_from_ro_product_board( |
| 2347 | const char ro_product_board[restrict static CPUINFO_BUILD_PROP_VALUE_MAX], |
| 2348 | uint32_t cores, uint32_t max_cpu_freq_max) |
| 2349 | { |
| 2350 | struct cpuinfo_arm_chipset chipset; |
| 2351 | const char* board = ro_product_board; |
| 2352 | const size_t board_length = strnlen(ro_product_board, CPUINFO_BUILD_PROP_VALUE_MAX); |
| 2353 | const char* board_end = ro_product_board + board_length; |
| 2354 | |
| 2355 | /* Check Qualcomm MSM/APQ signature */ |
| 2356 | if (match_msm_apq(board, board_end, &chipset)) { |
| 2357 | cpuinfo_log_debug( |
| 2358 | "matched Qualcomm MSM/APQ signature in ro.product.board string \"%.*s\"", (int) board_length, board); |
| 2359 | return chipset; |
| 2360 | } |
| 2361 | |
| 2362 | /* Check universaXXXX (Samsung Exynos) signature */ |
| 2363 | if (match_universal(board, board_end, &chipset)) { |
| 2364 | cpuinfo_log_debug( |
| 2365 | "matched UNIVERSAL (Samsung Exynos) signature in ro.product.board string \"%.*s\"", |
| 2366 | (int) board_length, board); |
| 2367 | return chipset; |
| 2368 | } |
| 2369 | |
| 2370 | /* Check SMDK (Samsung Exynos) signature */ |
| 2371 | if (match_and_parse_smdk(board, board_end, cores, &chipset)) { |
| 2372 | cpuinfo_log_debug( |
| 2373 | "matched SMDK (Samsung Exynos) signature in ro.product.board string \"%.*s\"", |
| 2374 | (int) board_length, board); |
| 2375 | return chipset; |
| 2376 | } |
| 2377 | |
| 2378 | /* Check MediaTek MT signature */ |
| 2379 | if (match_mt(board, board_end, true, &chipset)) { |
| 2380 | cpuinfo_log_debug( |
| 2381 | "matched MediaTek MT signature in ro.product.board string \"%.*s\"", |
| 2382 | (int) board_length, board); |
| 2383 | return chipset; |
| 2384 | } |
| 2385 | |
| 2386 | /* Check Spreadtrum SC signature */ |
| 2387 | if (match_sc(board, board_end, &chipset)) { |
| 2388 | cpuinfo_log_debug( |
| 2389 | "matched Spreadtrum SC signature in ro.product.board string \"%.*s\"", |
| 2390 | (int) board_length, board); |
| 2391 | return chipset; |
| 2392 | } |
| 2393 | |
| 2394 | /* Check Marvell PXA signature */ |
| 2395 | if (match_pxa(board, board_end, &chipset)) { |
| 2396 | cpuinfo_log_debug( |
| 2397 | "matched Marvell PXA signature in ro.product.board string \"%.*s\"", |
| 2398 | (int) board_length, board); |
| 2399 | return chipset; |
| 2400 | } |
| 2401 | |
| 2402 | /* Check Leadcore LCxxxx signature */ |
| 2403 | if (match_lc(board, board_end, &chipset)) { |
| 2404 | cpuinfo_log_debug( |
| 2405 | "matched Leadcore LC signature in ro.product.board string \"%.*s\"", |
| 2406 | (int) board_length, board); |
| 2407 | return chipset; |
| 2408 | } |
| 2409 | |
| 2410 | /* |
| 2411 | * Compare to tabulated ro.product.board values for Broadcom chipsets and decode chipset from frequency and |
| 2412 | * number of cores. |
| 2413 | */ |
| 2414 | if (match_and_parse_broadcom(board, board_end, cores, max_cpu_freq_max, &chipset)) { |
| 2415 | cpuinfo_log_debug( |
| 2416 | "found ro.product.board string \"%.*s\" in Broadcom chipset table", |
| 2417 | (int) board_length, board); |
| 2418 | return chipset; |
| 2419 | } |
| 2420 | |
| 2421 | /* Compare to tabulated ro.product.board values for Huawei devices which don't report chipset elsewhere */ |
| 2422 | if (match_and_parse_huawei(board, board_end, &chipset)) { |
| 2423 | cpuinfo_log_debug( |
| 2424 | "found ro.product.board string \"%.*s\" in Huawei chipset table", |
| 2425 | (int) board_length, board); |
| 2426 | return chipset; |
| 2427 | } |
| 2428 | |
| 2429 | /* Compare to tabulated ro.product.board values for popular chipsets/devices which can't be otherwise detected */ |
| 2430 | for (size_t i = 0; i < CPUINFO_COUNT_OF(special_board_map_entries); i++) { |
| 2431 | if (strncmp(special_board_map_entries[i].platform, board, board_length) == 0 && |
| 2432 | special_board_map_entries[i].platform[board_length] == 0) |
| 2433 | { |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 2434 | cpuinfo_log_debug( |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame^] | 2435 | "found ro.product.board string \"%.*s\" in special chipset table", |
| 2436 | (int) board_length, board); |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 2437 | /* Create chipset name from entry */ |
| 2438 | return (struct cpuinfo_arm_chipset) { |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame^] | 2439 | .vendor = chipset_series_vendor[special_board_map_entries[i].series], |
| 2440 | .series = (enum cpuinfo_arm_chipset_series) special_board_map_entries[i].series, |
| 2441 | .model = special_board_map_entries[i].model, |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 2442 | .suffix = { |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame^] | 2443 | [0] = special_board_map_entries[i].suffix, |
| 2444 | /* The suffix of MSM8996PRO is truncated at the first letter, reconstruct it here. */ |
| 2445 | [1] = special_board_map_entries[i].suffix == 'P' ? 'R' : 0, |
| 2446 | [2] = special_board_map_entries[i].suffix == 'P' ? 'O' : 0, |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 2447 | }, |
| 2448 | }; |
| 2449 | } |
| 2450 | } |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 2451 | |
| 2452 | return (struct cpuinfo_arm_chipset) { |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame^] | 2453 | .vendor = cpuinfo_arm_chipset_vendor_unknown, |
| 2454 | .series = cpuinfo_arm_chipset_series_unknown, |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 2455 | }; |
| 2456 | } |
| 2457 | |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame^] | 2458 | struct amlogic_map_entry { |
| 2459 | char ro_board_platform[6]; |
| 2460 | uint16_t model; |
| 2461 | uint8_t series; |
| 2462 | char suffix[3]; |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 2463 | }; |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame^] | 2464 | |
| 2465 | static const struct amlogic_map_entry amlogic_map_entries[] = { |
| 2466 | { |
| 2467 | /* "meson3" -> Amlogic AML8726-M */ |
| 2468 | .ro_board_platform = "meson3", |
| 2469 | .series = cpuinfo_arm_chipset_series_amlogic_aml, |
| 2470 | .model = 8726, |
| 2471 | .suffix = "-M", |
| 2472 | }, |
| 2473 | { |
| 2474 | /* "meson6" -> Amlogic AML8726-MX */ |
| 2475 | .ro_board_platform = "meson6", |
| 2476 | .series = cpuinfo_arm_chipset_series_amlogic_aml, |
| 2477 | .model = 8726, |
| 2478 | .suffix = "-MX", |
| 2479 | }, |
| 2480 | { |
| 2481 | /* "meson8" -> Amlogic S805 */ |
| 2482 | .ro_board_platform = "meson8", |
| 2483 | .series = cpuinfo_arm_chipset_series_amlogic_s, |
| 2484 | .model = 805, |
| 2485 | }, |
| 2486 | { |
| 2487 | /* "gxbaby" -> Amlogic S905 */ |
| 2488 | .ro_board_platform = "gxbaby", |
| 2489 | .series = cpuinfo_arm_chipset_series_amlogic_s, |
| 2490 | .model = 905, |
| 2491 | }, |
| 2492 | { |
| 2493 | /* "gxl" -> Amlogic S905X */ |
| 2494 | .ro_board_platform = "gxl", |
| 2495 | .series = cpuinfo_arm_chipset_series_amlogic_s, |
| 2496 | .model = 905, |
| 2497 | .suffix = "X", |
| 2498 | }, |
| 2499 | { |
| 2500 | /* "gxm" -> Amlogic S912 */ |
| 2501 | .ro_board_platform = "gxm", |
| 2502 | .series = cpuinfo_arm_chipset_series_amlogic_s, |
| 2503 | .model = 912, |
| 2504 | }, |
| 2505 | }; |
| 2506 | |
| 2507 | static const struct special_map_entry special_platform_map_entries[] = { |
| 2508 | { |
| 2509 | /* "hi6620oem" -> HiSilicon Kirin 910T */ |
| 2510 | .platform = "hi6620oem", |
| 2511 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2512 | .model = 910, |
| 2513 | .suffix = 'T', |
| 2514 | }, |
| 2515 | { |
| 2516 | /* "hi6250" -> HiSilicon Kirin 650 */ |
| 2517 | .platform = "hi6250", |
| 2518 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2519 | .model = 650, |
| 2520 | }, |
| 2521 | { |
| 2522 | /* "hi6210sft" -> HiSilicon Kirin 620 */ |
| 2523 | .platform = "hi6210sft", |
| 2524 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2525 | .model = 620, |
| 2526 | }, |
| 2527 | { |
| 2528 | /* "hi3650" -> HiSilicon Kirin 950 */ |
| 2529 | .platform = "hi3650", |
| 2530 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2531 | .model = 950, |
| 2532 | }, |
| 2533 | { |
| 2534 | /* "hi3635" -> HiSilicon Kirin 930 */ |
| 2535 | .platform = "hi3635", |
| 2536 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2537 | .model = 930, |
| 2538 | }, |
| 2539 | { |
| 2540 | /* "hi3630" -> HiSilicon Kirin 920 */ |
| 2541 | .platform = "hi3630", |
| 2542 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2543 | .model = 920, |
| 2544 | }, |
| 2545 | { |
| 2546 | /* "k3v2oem1" -> HiSilicon K3V2 */ |
| 2547 | .platform = "k3v2oem1", |
| 2548 | .series = cpuinfo_arm_chipset_series_hisilicon_k3v, |
| 2549 | .model = 2, |
| 2550 | }, |
| 2551 | { |
| 2552 | /* "k3v200" -> HiSilicon K3V2 */ |
| 2553 | .platform = "k3v200", |
| 2554 | .series = cpuinfo_arm_chipset_series_hisilicon_k3v, |
| 2555 | .model = 2, |
| 2556 | }, |
| 2557 | { |
| 2558 | /* "montblanc" -> NovaThor U8500 */ |
| 2559 | .platform = "montblanc", |
| 2560 | .series = cpuinfo_arm_chipset_series_novathor_u, |
| 2561 | .model = 8500, |
| 2562 | }, |
| 2563 | { |
| 2564 | /* "song" -> Pinecone Surge S1 */ |
| 2565 | .platform = "song", |
| 2566 | .series = cpuinfo_arm_chipset_series_pinecone_surge_s, |
| 2567 | .model = 1, |
| 2568 | }, |
| 2569 | { |
| 2570 | /* "tegra132" -> nVidia Tegra T132 */ |
| 2571 | .platform = "tegra132", |
| 2572 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 2573 | .model = 132, |
| 2574 | }, |
| 2575 | { |
| 2576 | /* "tegra210_dragon" -> nVidia Tegra T210 */ |
| 2577 | .platform = "tegra210_dragon", |
| 2578 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 2579 | .model = 210, |
| 2580 | }, |
| 2581 | { |
| 2582 | /* "tegra4" -> nVidia Tegra T114 */ |
| 2583 | .platform = "tegra4", |
| 2584 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 2585 | .model = 114, |
| 2586 | }, |
| 2587 | { |
| 2588 | /* "s5pc110" -> Samsung Exynos 3110 */ |
| 2589 | .platform = "s5pc110", |
| 2590 | .series = cpuinfo_arm_chipset_series_samsung_exynos, |
| 2591 | .model = 3110, |
| 2592 | }, |
| 2593 | }; |
| 2594 | |
| 2595 | /* |
| 2596 | * Decodes chipset name from ro.board.platform Android system property. |
| 2597 | * For some chipsets, the function relies frequency and on number of cores for chipset detection. |
| 2598 | * |
| 2599 | * @param[in] platform - ro.board.platform value. |
| 2600 | * @param cores - number of cores in the chipset. |
| 2601 | * @param max_cpu_freq_max - maximum of /sys/devices/system/cpu/cpu<number>/cpofreq/cpu_freq_max values. |
| 2602 | * |
| 2603 | * @returns Decoded chipset name. If chipset could not be decoded, the resulting structure would use `unknown` vendor |
| 2604 | * and series identifiers. |
| 2605 | */ |
| 2606 | struct cpuinfo_arm_chipset cpuinfo_arm_android_decode_chipset_from_ro_board_platform( |
| 2607 | const char platform[restrict static CPUINFO_BUILD_PROP_VALUE_MAX], |
| 2608 | uint32_t cores, uint32_t max_cpu_freq_max) |
| 2609 | { |
| 2610 | struct cpuinfo_arm_chipset chipset; |
| 2611 | const size_t platform_length = strnlen(platform, CPUINFO_BUILD_PROP_VALUE_MAX); |
| 2612 | const char* platform_end = platform + platform_length; |
| 2613 | |
| 2614 | /* Check Qualcomm MSM/APQ signature */ |
| 2615 | if (match_msm_apq(platform, platform_end, &chipset)) { |
| 2616 | cpuinfo_log_debug( |
| 2617 | "matched Qualcomm MSM/APQ signature in ro.board.platform string \"%.*s\"", |
| 2618 | (int) platform_length, platform); |
| 2619 | return chipset; |
| 2620 | } |
| 2621 | |
| 2622 | /* Check exynosXXXX (Samsung Exynos) signature */ |
| 2623 | if (match_exynos(platform, platform_end, &chipset)) { |
| 2624 | cpuinfo_log_debug( |
| 2625 | "matched exynosXXXX (Samsung Exynos) signature in ro.board.platform string \"%.*s\"", |
| 2626 | (int) platform_length, platform); |
| 2627 | return chipset; |
| 2628 | } |
| 2629 | |
| 2630 | /* Check MediaTek MT signature */ |
| 2631 | if (match_mt(platform, platform_end, true, &chipset)) { |
| 2632 | cpuinfo_log_debug( |
| 2633 | "matched MediaTek MT signature in ro.board.platform string \"%.*s\"", (int) platform_length, platform); |
| 2634 | return chipset; |
| 2635 | } |
| 2636 | |
| 2637 | /* Check Spreadtrum SC signature */ |
| 2638 | if (match_sc(platform, platform_end, &chipset)) { |
| 2639 | cpuinfo_log_debug( |
| 2640 | "matched Spreadtrum SC signature in ro.board.platform string \"%.*s\"", (int) platform_length, platform); |
| 2641 | return chipset; |
| 2642 | } |
| 2643 | |
| 2644 | /* Check Rockchip RK signature */ |
| 2645 | if (match_rk(platform, platform_end, &chipset)) { |
| 2646 | cpuinfo_log_debug( |
| 2647 | "matched Rockchip RK signature in ro.board.platform string \"%.*s\"", (int) platform_length, platform); |
| 2648 | return chipset; |
| 2649 | } |
| 2650 | |
| 2651 | /* Check Leadcore LCxxxx signature */ |
| 2652 | if (match_lc(platform, platform_end, &chipset)) { |
| 2653 | cpuinfo_log_debug( |
| 2654 | "matched Leadcore LC signature in ro.board.platform string \"%.*s\"", (int) platform_length, platform); |
| 2655 | return chipset; |
| 2656 | } |
| 2657 | |
| 2658 | /* Compare to tabulated ro.board.platform values for Huawei devices which don't report chipset elsewhere */ |
| 2659 | if (match_and_parse_huawei(platform, platform_end, &chipset)) { |
| 2660 | cpuinfo_log_debug( |
| 2661 | "found ro.board.platform string \"%.*s\" in Huawei chipset table", |
| 2662 | (int) platform_length, platform); |
| 2663 | return chipset; |
| 2664 | } |
| 2665 | |
| 2666 | /* |
| 2667 | * Compare to known ro.board.platform values for Broadcom devices and |
| 2668 | * detect chipset from frequency and number of cores |
| 2669 | */ |
| 2670 | if (match_and_parse_broadcom(platform, platform_end, cores, max_cpu_freq_max, &chipset)) { |
| 2671 | cpuinfo_log_debug( |
| 2672 | "found ro.board.platform string \"%.*s\" in Broadcom chipset table", |
| 2673 | (int) platform_length, platform); |
| 2674 | return chipset; |
| 2675 | } |
| 2676 | |
| 2677 | /* |
| 2678 | * Compare to ro.board.platform value ("omap4") for OMAP4xxx chipsets. |
| 2679 | * Upon successful match, detect OMAP4430 from frequency and number of cores. |
| 2680 | */ |
| 2681 | if (platform_length == 5 && cores == 2 && max_cpu_freq_max == 1008000 && memcmp(platform, "omap4", 5) == 0) { |
| 2682 | cpuinfo_log_debug( |
| 2683 | "matched Texas Instruments OMAP4 signature in ro.board.platform string \"%.*s\"", |
| 2684 | (int) platform_length, platform); |
| 2685 | |
| 2686 | return (struct cpuinfo_arm_chipset) { |
| 2687 | .vendor = cpuinfo_arm_chipset_vendor_texas_instruments, |
| 2688 | .series = cpuinfo_arm_chipset_series_texas_instruments_omap, |
| 2689 | .model = 4430, |
| 2690 | }; |
| 2691 | } |
| 2692 | |
| 2693 | /* |
| 2694 | * Compare to tabulated ro.board.platform values for Amlogic chipsets/devices which can't be otherwise detected. |
| 2695 | * The tabulated Amlogic ro.board.platform values have not more than 6 characters. |
| 2696 | */ |
| 2697 | if (platform_length <= 6) { |
| 2698 | for (size_t i = 0; i < CPUINFO_COUNT_OF(amlogic_map_entries); i++) { |
| 2699 | if (strncmp(amlogic_map_entries[i].ro_board_platform, platform, 6) == 0) { |
| 2700 | cpuinfo_log_debug( |
| 2701 | "found ro.board.platform string \"%.*s\" in Amlogic chipset table", |
| 2702 | (int) platform_length, platform); |
| 2703 | /* Create chipset name from entry */ |
| 2704 | return (struct cpuinfo_arm_chipset) { |
| 2705 | .vendor = cpuinfo_arm_chipset_vendor_amlogic, |
| 2706 | .series = (enum cpuinfo_arm_chipset_series) amlogic_map_entries[i].series, |
| 2707 | .model = amlogic_map_entries[i].model, |
| 2708 | .suffix = { |
| 2709 | [0] = amlogic_map_entries[i].suffix[0], |
| 2710 | [1] = amlogic_map_entries[i].suffix[1], |
| 2711 | [2] = amlogic_map_entries[i].suffix[2], |
| 2712 | }, |
| 2713 | }; |
| 2714 | } |
| 2715 | } |
| 2716 | } |
| 2717 | |
| 2718 | /* Compare to tabulated ro.board.platform values for popular chipsets/devices which can't be otherwise detected */ |
| 2719 | for (size_t i = 0; i < CPUINFO_COUNT_OF(special_platform_map_entries); i++) { |
| 2720 | if (strncmp(special_platform_map_entries[i].platform, platform, platform_length) == 0 && |
| 2721 | special_platform_map_entries[i].platform[platform_length] == 0) |
| 2722 | { |
| 2723 | /* Create chipset name from entry */ |
| 2724 | cpuinfo_log_debug( |
| 2725 | "found ro.board.platform string \"%.*s\" in special chipset table", (int) platform_length, platform); |
| 2726 | return (struct cpuinfo_arm_chipset) { |
| 2727 | .vendor = chipset_series_vendor[special_platform_map_entries[i].series], |
| 2728 | .series = (enum cpuinfo_arm_chipset_series) special_platform_map_entries[i].series, |
| 2729 | .model = special_platform_map_entries[i].model, |
| 2730 | .suffix = { |
| 2731 | [0] = special_platform_map_entries[i].suffix, |
| 2732 | }, |
| 2733 | }; |
| 2734 | } |
| 2735 | } |
| 2736 | |
| 2737 | /* None of the ro.board.platform signatures matched, indicate unknown chipset */ |
| 2738 | return (struct cpuinfo_arm_chipset) { |
| 2739 | .vendor = cpuinfo_arm_chipset_vendor_unknown, |
| 2740 | .series = cpuinfo_arm_chipset_series_unknown, |
| 2741 | }; |
| 2742 | } |
| 2743 | |
| 2744 | /* |
| 2745 | * Decodes chipset name from ro.mediatek.platform Android system property. |
| 2746 | * |
| 2747 | * @param[in] platform - ro.mediatek.platform value. |
| 2748 | * |
| 2749 | * @returns Decoded chipset name. If chipset could not be decoded, the resulting structure would use `unknown` vendor |
| 2750 | * and series identifiers. |
| 2751 | */ |
| 2752 | struct cpuinfo_arm_chipset cpuinfo_arm_android_decode_chipset_from_ro_mediatek_platform( |
| 2753 | const char platform[restrict static CPUINFO_BUILD_PROP_VALUE_MAX]) |
| 2754 | { |
| 2755 | struct cpuinfo_arm_chipset chipset; |
| 2756 | const char* platform_end = platform + strnlen(platform, CPUINFO_BUILD_PROP_VALUE_MAX);; |
| 2757 | |
| 2758 | /* Check MediaTek MT signature */ |
| 2759 | if (match_mt(platform, platform_end, false, &chipset)) { |
| 2760 | return chipset; |
| 2761 | } |
| 2762 | |
| 2763 | return (struct cpuinfo_arm_chipset) { |
| 2764 | .vendor = cpuinfo_arm_chipset_vendor_unknown, |
| 2765 | .series = cpuinfo_arm_chipset_series_unknown, |
| 2766 | }; |
| 2767 | } |
| 2768 | |
| 2769 | /* |
| 2770 | * Decodes chipset name from ro.chipname Android system property. |
| 2771 | * |
| 2772 | * @param[in] chipname - ro.chipname value. |
| 2773 | * |
| 2774 | * @returns Decoded chipset name. If chipset could not be decoded, the resulting structure would use `unknown` vendor |
| 2775 | * and series identifiers. |
| 2776 | */ |
| 2777 | struct cpuinfo_arm_chipset cpuinfo_arm_android_decode_chipset_from_ro_chipname( |
| 2778 | const char chipname[restrict static CPUINFO_BUILD_PROP_VALUE_MAX]) |
| 2779 | { |
| 2780 | struct cpuinfo_arm_chipset chipset; |
| 2781 | const size_t chipname_length = strnlen(chipname, CPUINFO_BUILD_PROP_VALUE_MAX); |
| 2782 | const char* chipname_end = chipname + chipname_length; |
| 2783 | |
| 2784 | /* Check Qualcomm MSM/APQ signatures */ |
| 2785 | if (match_msm_apq(chipname, chipname_end, &chipset)) { |
| 2786 | cpuinfo_log_debug( |
| 2787 | "matched Qualcomm MSM/APQ signature in ro.chipname string \"%.*s\"", |
| 2788 | (int) chipname_length, chipname); |
| 2789 | return chipset; |
| 2790 | } |
| 2791 | |
| 2792 | /* Check exynosXXXX (Samsung Exynos) signature */ |
| 2793 | if (match_exynos(chipname, chipname_end, &chipset)) { |
| 2794 | cpuinfo_log_debug( |
| 2795 | "matched exynosXXXX (Samsung Exynos) signature in ro.chipname string \"%.*s\"", |
| 2796 | (int) chipname_length, chipname); |
| 2797 | return chipset; |
| 2798 | } |
| 2799 | |
| 2800 | /* Check universalXXXX (Samsung Exynos) signature */ |
| 2801 | if (match_universal(chipname, chipname_end, &chipset)) { |
| 2802 | cpuinfo_log_debug( |
| 2803 | "matched UNIVERSAL (Samsung Exynos) signature in ro.chipname Hardware string \"%.*s\"", |
| 2804 | (int) chipname_length, chipname); |
| 2805 | return chipset; |
| 2806 | } |
| 2807 | |
| 2808 | /* Check MediaTek MT signature */ |
| 2809 | if (match_mt(chipname, chipname_end, true, &chipset)) { |
| 2810 | cpuinfo_log_debug( |
| 2811 | "matched MediaTek MT signature in ro.chipname string \"%.*s\"", |
| 2812 | (int) chipname_length, chipname); |
| 2813 | return chipset; |
| 2814 | } |
| 2815 | |
| 2816 | /* Check Spreadtrum SC signature */ |
| 2817 | if (match_sc(chipname, chipname_end, &chipset)) { |
| 2818 | cpuinfo_log_debug( |
| 2819 | "matched Spreadtrum SC signature in ro.chipname string \"%.*s\"", |
| 2820 | (int) chipname_length, chipname); |
| 2821 | return chipset; |
| 2822 | } |
| 2823 | |
| 2824 | /* Check Marvell PXA signature */ |
| 2825 | if (match_pxa(chipname, chipname_end, &chipset)) { |
| 2826 | cpuinfo_log_debug( |
| 2827 | "matched Marvell PXA signature in ro.chipname string \"%.*s\"", |
| 2828 | (int) chipname_length, chipname); |
| 2829 | return chipset; |
| 2830 | } |
| 2831 | |
| 2832 | /* Compare to ro.chipname value ("mp523x") for Renesas MP5232 which can't be otherwise detected */ |
| 2833 | if (chipname_length == 6 && memcmp(chipname, "mp523x", 6) == 0) { |
| 2834 | cpuinfo_log_debug( |
| 2835 | "matched Renesas MP5232 signature in ro.chipname string \"%.*s\"", |
| 2836 | (int) chipname_length, chipname); |
| 2837 | |
| 2838 | return (struct cpuinfo_arm_chipset) { |
| 2839 | .vendor = cpuinfo_arm_chipset_vendor_renesas, |
| 2840 | .series = cpuinfo_arm_chipset_series_renesas_mp, |
| 2841 | .model = 5232, |
| 2842 | }; |
| 2843 | } |
| 2844 | |
| 2845 | return (struct cpuinfo_arm_chipset) { |
| 2846 | .vendor = cpuinfo_arm_chipset_vendor_unknown, |
| 2847 | .series = cpuinfo_arm_chipset_series_unknown, |
| 2848 | }; |
| 2849 | } |
| 2850 | #endif /* __ANDROID__ */ |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 2851 | |
| 2852 | /* |
| 2853 | * Fix common bugs, typos, and renames in chipset name. |
| 2854 | * |
| 2855 | * @param[in,out] chipset - chipset name to fix. |
| 2856 | * @param cores - number of cores in the chipset. |
| 2857 | * @param max_cpu_freq_max - maximum of /sys/devices/system/cpu/cpu<number>/cpofreq/cpu_freq_max values. |
| 2858 | */ |
| 2859 | void cpuinfo_arm_fixup_chipset( |
| 2860 | struct cpuinfo_arm_chipset chipset[restrict static 1], uint32_t cores, uint32_t max_cpu_freq_max) |
| 2861 | { |
| 2862 | switch (chipset->series) { |
| 2863 | case cpuinfo_arm_chipset_series_qualcomm_msm: |
| 2864 | /* Check if there is suffix */ |
| 2865 | if (chipset->suffix[0] == 0) { |
| 2866 | /* No suffix, but the model may be misreported */ |
| 2867 | switch (chipset->model) { |
| 2868 | case 8216: |
| 2869 | /* MSM8216 was renamed to MSM8916 */ |
| 2870 | cpuinfo_log_info("reinterpreted MSM8216 chipset as MSM8916"); |
| 2871 | chipset->model = 8916; |
| 2872 | break; |
| 2873 | case 8916: |
| 2874 | /* Common bug: MSM8939 (Octa-core) reported as MSM8916 (Quad-core) */ |
| 2875 | switch (cores) { |
| 2876 | case 4: |
| 2877 | break; |
| 2878 | case 8: |
| 2879 | cpuinfo_log_info("reinterpreted MSM8916 chipset with 8 cores as MSM8939"); |
| 2880 | chipset->model = 8939; |
| 2881 | break; |
| 2882 | default: |
| 2883 | cpuinfo_log_warning("system reported invalid %"PRIu32"-core MSM%"PRIu32" chipset", |
| 2884 | cores, chipset->model); |
| 2885 | chipset->model = 0; |
| 2886 | } |
| 2887 | break; |
| 2888 | case 8937: |
| 2889 | /* Common bug: MSM8917 (Quad-core) reported as MSM8937 (Octa-core) */ |
| 2890 | switch (cores) { |
| 2891 | case 4: |
| 2892 | cpuinfo_log_info("reinterpreted MSM8937 chipset with 4 cores as MSM8917"); |
| 2893 | chipset->model = 8917; |
| 2894 | break; |
| 2895 | case 8: |
| 2896 | break; |
| 2897 | default: |
| 2898 | cpuinfo_log_warning("system reported invalid %"PRIu32"-core MSM%"PRIu32" chipset", |
| 2899 | cores, chipset->model); |
| 2900 | chipset->model = 0; |
| 2901 | } |
| 2902 | break; |
| 2903 | case 8960: |
| 2904 | /* Common bug: APQ8064 (Quad-core) reported as MSM8960 (Dual-core) */ |
| 2905 | switch (cores) { |
| 2906 | case 2: |
| 2907 | break; |
| 2908 | case 4: |
| 2909 | cpuinfo_log_info("reinterpreted MSM8960 chipset with 4 cores as APQ8064"); |
| 2910 | chipset->series = cpuinfo_arm_chipset_series_qualcomm_apq; |
| 2911 | chipset->model = 8064; |
| 2912 | break; |
| 2913 | default: |
| 2914 | cpuinfo_log_warning("system reported invalid %"PRIu32"-core MSM%"PRIu32" chipset", |
| 2915 | cores, chipset->model); |
| 2916 | chipset->model = 0; |
| 2917 | } |
| 2918 | break; |
| 2919 | case 8996: |
| 2920 | /* Common bug: MSM8994 (Octa-core) reported as MSM8996 (Quad-core) */ |
| 2921 | switch (cores) { |
| 2922 | case 4: |
| 2923 | break; |
| 2924 | case 8: |
| 2925 | cpuinfo_log_info("reinterpreted MSM8996 chipset with 8 cores as MSM8994"); |
| 2926 | chipset->model = 8994; |
| 2927 | break; |
| 2928 | default: |
| 2929 | cpuinfo_log_warning("system reported invalid %"PRIu32"-core MSM%"PRIu32" chipset", |
| 2930 | cores, chipset->model); |
| 2931 | chipset->model = 0; |
| 2932 | } |
| 2933 | break; |
| 2934 | case 8610: |
| 2935 | /* Common bug: MSM8212 (Quad-core) reported as MSM8610 (Dual-core) */ |
| 2936 | switch (cores) { |
| 2937 | case 2: |
| 2938 | break; |
| 2939 | case 4: |
| 2940 | cpuinfo_log_info("reinterpreted MSM8610 chipset with 4 cores as MSM8212"); |
| 2941 | chipset->model = 8212; |
| 2942 | break; |
| 2943 | default: |
| 2944 | cpuinfo_log_warning("system reported invalid %"PRIu32"-core MSM%"PRIu32" chipset", |
| 2945 | cores, chipset->model); |
| 2946 | chipset->model = 0; |
| 2947 | } |
| 2948 | break; |
| 2949 | } |
| 2950 | } else { |
| 2951 | /* Suffix may need correction */ |
| 2952 | const uint32_t suffix_word = load_u32le(chipset->suffix); |
| 2953 | if (suffix_word == UINT32_C(0x004D534D) /* "\0MSM" = reverse("MSM\0") */) { |
| 2954 | /* |
| 2955 | * Common bug: model name repeated twice, e.g. "MSM8916MSM8916" |
| 2956 | * In this case, model matching code parses the second "MSM" as a suffix |
| 2957 | */ |
| 2958 | chipset->suffix[0] = 0; |
| 2959 | chipset->suffix[1] = 0; |
| 2960 | chipset->suffix[2] = 0; |
| 2961 | } else { |
| 2962 | switch (chipset->model) { |
| 2963 | case 8976: |
| 2964 | /* MSM8976SG -> MSM8976PRO */ |
| 2965 | if (suffix_word == UINT32_C(0x00004753) /* "\0\0GS" = reverse("SG\0\0") */ ) { |
| 2966 | chipset->suffix[0] = 'P'; |
| 2967 | chipset->suffix[1] = 'R'; |
| 2968 | chipset->suffix[2] = 'O'; |
| 2969 | } |
| 2970 | break; |
| 2971 | case 8996: |
| 2972 | /* MSM8996PRO -> MSM8996PRO-AB or MSM8996PRO-AC */ |
| 2973 | if (suffix_word == UINT32_C(0x004F5250) /* "\0ORP" = reverse("PRO\0") */ ) { |
| 2974 | chipset->suffix[3] = '-'; |
| 2975 | chipset->suffix[4] = 'A'; |
| 2976 | chipset->suffix[5] = 'B' + (char) (max_cpu_freq_max >= 2188800); |
| 2977 | } |
| 2978 | break; |
| 2979 | } |
| 2980 | } |
| 2981 | } |
| 2982 | break; |
| 2983 | case cpuinfo_arm_chipset_series_qualcomm_apq: |
| 2984 | { |
| 2985 | /* Suffix may need correction */ |
| 2986 | const uint32_t expected_apq = load_u32le(chipset->suffix); |
| 2987 | if (expected_apq == UINT32_C(0x00515041) /* "\0QPA" = reverse("APQ\0") */) { |
| 2988 | /* |
| 2989 | * Common bug: model name repeated twice, e.g. "APQ8016APQ8016" |
| 2990 | * In this case, model matching code parses the second "APQ" as a suffix |
| 2991 | */ |
| 2992 | chipset->suffix[0] = 0; |
| 2993 | chipset->suffix[1] = 0; |
| 2994 | chipset->suffix[2] = 0; |
| 2995 | } |
| 2996 | break; |
| 2997 | } |
| 2998 | case cpuinfo_arm_chipset_series_samsung_exynos: |
| 2999 | if (chipset->model == 7580) { |
| 3000 | /* Common bug: Exynos 7578 (Quad-core) reported as Exynos 7580 (Octa-core) */ |
| 3001 | switch (cores) { |
| 3002 | case 4: |
| 3003 | cpuinfo_log_info("reinterpreted Exynos 7580 chipset with 4 cores as Exynos 7578"); |
| 3004 | chipset->model = 7578; |
| 3005 | break; |
| 3006 | case 8: |
| 3007 | break; |
| 3008 | default: |
| 3009 | cpuinfo_log_warning("system reported invalid %"PRIu32"-core Exynos 7580 chipset", cores); |
| 3010 | chipset->model = 0; |
| 3011 | } |
| 3012 | } |
| 3013 | break; |
| 3014 | case cpuinfo_arm_chipset_series_mediatek_mt: |
| 3015 | if (chipset->model == 6752) { |
| 3016 | /* Common bug: MT6732 (Quad-core) reported as MT6752 (Octa-core) */ |
| 3017 | switch (cores) { |
| 3018 | case 4: |
| 3019 | cpuinfo_log_info("reinterpreted MT6752 chipset with 4 cores as MT6732"); |
| 3020 | chipset->model = 6732; |
| 3021 | break; |
| 3022 | case 8: |
| 3023 | break; |
| 3024 | default: |
| 3025 | cpuinfo_log_warning("system reported invalid %"PRIu32"-core MT6752 chipset", cores); |
| 3026 | chipset->model = 0; |
| 3027 | } |
| 3028 | } |
| 3029 | if (chipset->suffix[0] == 'T') { |
| 3030 | /* Normalization: "TURBO" and "TRUBO" (apparently a typo) -> "T" */ |
| 3031 | const uint32_t suffix_word = load_u32le(chipset->suffix + 1); |
| 3032 | switch (suffix_word) { |
| 3033 | case UINT32_C(0x4F425255): /* "OBRU" = reverse("URBO") */ |
| 3034 | case UINT32_C(0x4F425552): /* "OBUR" = reverse("RUBO") */ |
| 3035 | if (chipset->suffix[5] == 0) { |
| 3036 | chipset->suffix[1] = 0; |
| 3037 | chipset->suffix[2] = 0; |
| 3038 | chipset->suffix[3] = 0; |
| 3039 | chipset->suffix[4] = 0; |
| 3040 | } |
| 3041 | break; |
| 3042 | } |
| 3043 | } |
| 3044 | break; |
| 3045 | default: |
| 3046 | break; |
| 3047 | } |
| 3048 | } |
| 3049 | |
| 3050 | /* Map from ARM chipset vendor ID to its string representation */ |
| 3051 | static const char* chipset_vendor_string[cpuinfo_arm_chipset_vendor_max] = { |
| 3052 | [cpuinfo_arm_chipset_vendor_unknown] = "Unknown", |
| 3053 | [cpuinfo_arm_chipset_vendor_qualcomm] = "Qualcomm", |
| 3054 | [cpuinfo_arm_chipset_vendor_mediatek] = "MediaTek", |
| 3055 | [cpuinfo_arm_chipset_vendor_samsung] = "Samsung", |
| 3056 | [cpuinfo_arm_chipset_vendor_hisilicon] = "HiSilicon", |
| 3057 | [cpuinfo_arm_chipset_vendor_actions] = "Actions", |
| 3058 | [cpuinfo_arm_chipset_vendor_allwinner] = "Allwinner", |
| 3059 | [cpuinfo_arm_chipset_vendor_amlogic] = "Amlogic", |
| 3060 | [cpuinfo_arm_chipset_vendor_broadcom] = "Broadcom", |
| 3061 | [cpuinfo_arm_chipset_vendor_lg] = "LG", |
| 3062 | [cpuinfo_arm_chipset_vendor_leadcore] = "Leadcore", |
| 3063 | [cpuinfo_arm_chipset_vendor_marvell] = "Marvell", |
| 3064 | [cpuinfo_arm_chipset_vendor_mstar] = "MStar", |
| 3065 | [cpuinfo_arm_chipset_vendor_novathor] = "NovaThor", |
| 3066 | [cpuinfo_arm_chipset_vendor_nvidia] = "nVidia", |
| 3067 | [cpuinfo_arm_chipset_vendor_pinecone] = "Pinecone", |
| 3068 | [cpuinfo_arm_chipset_vendor_renesas] = "Renesas", |
| 3069 | [cpuinfo_arm_chipset_vendor_rockchip] = "Rockchip", |
| 3070 | [cpuinfo_arm_chipset_vendor_spreadtrum] = "Spreadtrum", |
| 3071 | [cpuinfo_arm_chipset_vendor_telechips] = "Telechips", |
| 3072 | [cpuinfo_arm_chipset_vendor_texas_instruments] = "Texas Instruments", |
| 3073 | [cpuinfo_arm_chipset_vendor_wondermedia] = "WonderMedia", |
| 3074 | }; |
| 3075 | |
| 3076 | /* Map from ARM chipset series ID to its string representation */ |
| 3077 | static const char* chipset_series_string[cpuinfo_arm_chipset_series_max] = { |
| 3078 | [cpuinfo_arm_chipset_series_unknown] = NULL, |
| 3079 | [cpuinfo_arm_chipset_series_qualcomm_qsd] = "QSD", |
| 3080 | [cpuinfo_arm_chipset_series_qualcomm_msm] = "MSM", |
| 3081 | [cpuinfo_arm_chipset_series_qualcomm_apq] = "APQ", |
| 3082 | [cpuinfo_arm_chipset_series_qualcomm_snapdragon] = "Snapdragon ", |
| 3083 | [cpuinfo_arm_chipset_series_mediatek_mt] = "MT", |
| 3084 | [cpuinfo_arm_chipset_series_samsung_exynos] = "Exynos ", |
| 3085 | [cpuinfo_arm_chipset_series_hisilicon_k3v] = "K3V", |
| 3086 | [cpuinfo_arm_chipset_series_hisilicon_hi] = "Hi", |
| 3087 | [cpuinfo_arm_chipset_series_hisilicon_kirin] = "Kirin ", |
| 3088 | [cpuinfo_arm_chipset_series_actions_atm] = "ATM", |
| 3089 | [cpuinfo_arm_chipset_series_allwinner_a] = "A", |
| 3090 | [cpuinfo_arm_chipset_series_amlogic_aml] = "AML", |
| 3091 | [cpuinfo_arm_chipset_series_amlogic_s] = "S", |
| 3092 | [cpuinfo_arm_chipset_series_broadcom_bcm] = "BCM", |
| 3093 | [cpuinfo_arm_chipset_series_lg_nuclun] = "Nuclun ", |
| 3094 | [cpuinfo_arm_chipset_series_leadcore_lc] = "LC", |
| 3095 | [cpuinfo_arm_chipset_series_marvell_pxa] = "PXA", |
| 3096 | [cpuinfo_arm_chipset_series_mstar_6a] = "6A", |
| 3097 | [cpuinfo_arm_chipset_series_novathor_u] = "U", |
| 3098 | [cpuinfo_arm_chipset_series_nvidia_tegra_t] = "Tegra T", |
| 3099 | [cpuinfo_arm_chipset_series_nvidia_tegra_ap] = "Tegra AP", |
| 3100 | [cpuinfo_arm_chipset_series_nvidia_tegra_sl] = "Tegra SL", |
| 3101 | [cpuinfo_arm_chipset_series_pinecone_surge_s] = "Surge S", |
| 3102 | [cpuinfo_arm_chipset_series_renesas_mp] = "MP", |
| 3103 | [cpuinfo_arm_chipset_series_rockchip_rk] = "RK", |
| 3104 | [cpuinfo_arm_chipset_series_spreadtrum_sc] = "SC", |
| 3105 | [cpuinfo_arm_chipset_series_telechips_tcc] = "TCC", |
| 3106 | [cpuinfo_arm_chipset_series_texas_instruments_omap] = "OMAP", |
| 3107 | [cpuinfo_arm_chipset_series_wondermedia_wm] = "WM", |
| 3108 | }; |
| 3109 | |
| 3110 | /* Convert chipset name represented by cpuinfo_arm_chipset structure to a string representation */ |
| 3111 | void cpuinfo_arm_chipset_to_string( |
| 3112 | const struct cpuinfo_arm_chipset chipset[restrict static 1], |
| 3113 | char name[restrict static CPUINFO_ARM_CHIPSET_NAME_MAX]) |
| 3114 | { |
| 3115 | enum cpuinfo_arm_chipset_vendor vendor = chipset->vendor; |
| 3116 | if (vendor >= cpuinfo_arm_chipset_vendor_max) { |
| 3117 | vendor = cpuinfo_arm_chipset_vendor_unknown; |
| 3118 | } |
| 3119 | enum cpuinfo_arm_chipset_series series = chipset->series; |
| 3120 | if (series >= cpuinfo_arm_chipset_series_max) { |
| 3121 | series = cpuinfo_arm_chipset_series_unknown; |
| 3122 | } |
| 3123 | const char* vendor_string = chipset_vendor_string[vendor]; |
| 3124 | const char* series_string = chipset_series_string[series]; |
| 3125 | const uint32_t model = chipset->model; |
| 3126 | if (model == 0) { |
| 3127 | if (series == cpuinfo_arm_chipset_series_unknown) { |
| 3128 | strncpy(name, vendor_string, CPUINFO_ARM_CHIPSET_NAME_MAX); |
| 3129 | } else { |
| 3130 | snprintf(name, CPUINFO_ARM_CHIPSET_NAME_MAX, |
| 3131 | "%s %s", vendor_string, series_string); |
| 3132 | } |
| 3133 | } else { |
| 3134 | const size_t suffix_length = strnlen(chipset->suffix, CPUINFO_ARM_CHIPSET_SUFFIX_MAX); |
| 3135 | snprintf(name, CPUINFO_ARM_CHIPSET_NAME_MAX, |
| 3136 | "%s %s%"PRIu32"%.*s", vendor_string, series_string, model, (int) suffix_length, chipset->suffix); |
| 3137 | } |
| 3138 | } |
| 3139 | |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame^] | 3140 | #ifdef __ANDROID__ |
| 3141 | static inline struct cpuinfo_arm_chipset disambiguate_qualcomm_chipset( |
| 3142 | const struct cpuinfo_arm_chipset proc_cpuinfo_hardware_chipset[restrict static 1], |
| 3143 | const struct cpuinfo_arm_chipset ro_product_board_chipset[restrict static 1], |
| 3144 | const struct cpuinfo_arm_chipset ro_board_platform_chipset[restrict static 1], |
| 3145 | const struct cpuinfo_arm_chipset ro_chipname_chipset[restrict static 1]) |
| 3146 | { |
| 3147 | if (ro_chipname_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3148 | return *ro_chipname_chipset; |
| 3149 | } |
| 3150 | if (proc_cpuinfo_hardware_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3151 | return *proc_cpuinfo_hardware_chipset; |
| 3152 | } |
| 3153 | if (ro_product_board_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3154 | return *ro_product_board_chipset; |
| 3155 | } |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 3156 | return *ro_board_platform_chipset; |
| 3157 | } |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 3158 | |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame^] | 3159 | static inline struct cpuinfo_arm_chipset disambiguate_mediatek_chipset( |
| 3160 | const struct cpuinfo_arm_chipset proc_cpuinfo_hardware_chipset[restrict static 1], |
| 3161 | const struct cpuinfo_arm_chipset ro_product_board_chipset[restrict static 1], |
| 3162 | const struct cpuinfo_arm_chipset ro_board_platform_chipset[restrict static 1], |
| 3163 | const struct cpuinfo_arm_chipset ro_mediatek_platform_chipset[restrict static 1], |
| 3164 | const struct cpuinfo_arm_chipset ro_chipname_chipset[restrict static 1]) |
| 3165 | { |
| 3166 | if (ro_chipname_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3167 | return *ro_chipname_chipset; |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 3168 | } |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame^] | 3169 | if (proc_cpuinfo_hardware_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3170 | return *proc_cpuinfo_hardware_chipset; |
| 3171 | } |
| 3172 | if (ro_product_board_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3173 | return *ro_product_board_chipset; |
| 3174 | } |
| 3175 | if (ro_board_platform_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3176 | return *ro_board_platform_chipset; |
| 3177 | } |
| 3178 | return *ro_mediatek_platform_chipset; |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 3179 | } |
| 3180 | |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame^] | 3181 | static inline struct cpuinfo_arm_chipset disambiguate_hisilicon_chipset( |
| 3182 | const struct cpuinfo_arm_chipset proc_cpuinfo_hardware_chipset[restrict static 1], |
| 3183 | const struct cpuinfo_arm_chipset ro_product_board_chipset[restrict static 1], |
| 3184 | const struct cpuinfo_arm_chipset ro_board_platform_chipset[restrict static 1]) |
| 3185 | { |
| 3186 | if (proc_cpuinfo_hardware_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3187 | return *proc_cpuinfo_hardware_chipset; |
| 3188 | } |
| 3189 | if (ro_product_board_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3190 | return *ro_product_board_chipset; |
| 3191 | } |
| 3192 | return *ro_board_platform_chipset; |
| 3193 | } |
| 3194 | |
| 3195 | static inline struct cpuinfo_arm_chipset disambiguate_amlogic_chipset( |
| 3196 | const struct cpuinfo_arm_chipset proc_cpuinfo_hardware_chipset[restrict static 1], |
| 3197 | const struct cpuinfo_arm_chipset ro_board_platform_chipset[restrict static 1]) |
| 3198 | { |
| 3199 | if (proc_cpuinfo_hardware_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3200 | return *proc_cpuinfo_hardware_chipset; |
| 3201 | } |
| 3202 | return *ro_board_platform_chipset; |
| 3203 | } |
| 3204 | |
| 3205 | static inline struct cpuinfo_arm_chipset disambiguate_marvell_chipset( |
| 3206 | const struct cpuinfo_arm_chipset proc_cpuinfo_hardware_chipset[restrict static 1], |
| 3207 | const struct cpuinfo_arm_chipset ro_product_board_chipset[restrict static 1], |
| 3208 | const struct cpuinfo_arm_chipset ro_chipname_chipset[restrict static 1]) |
| 3209 | { |
| 3210 | if (ro_chipname_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3211 | return *ro_chipname_chipset; |
| 3212 | } |
| 3213 | if (ro_product_board_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3214 | return *ro_product_board_chipset; |
| 3215 | } |
| 3216 | return *proc_cpuinfo_hardware_chipset; |
| 3217 | } |
| 3218 | |
| 3219 | static inline struct cpuinfo_arm_chipset disambiguate_rockchip_chipset( |
| 3220 | const struct cpuinfo_arm_chipset proc_cpuinfo_hardware_chipset[restrict static 1], |
| 3221 | const struct cpuinfo_arm_chipset ro_product_board_chipset[restrict static 1], |
| 3222 | const struct cpuinfo_arm_chipset ro_board_platform_chipset[restrict static 1]) |
| 3223 | { |
| 3224 | if (ro_product_board_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3225 | return *ro_product_board_chipset; |
| 3226 | } |
| 3227 | if (proc_cpuinfo_hardware_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3228 | return *proc_cpuinfo_hardware_chipset; |
| 3229 | } |
| 3230 | return *ro_board_platform_chipset; |
| 3231 | } |
| 3232 | |
| 3233 | static inline struct cpuinfo_arm_chipset disambiguate_spreadtrum_chipset( |
| 3234 | const struct cpuinfo_arm_chipset proc_cpuinfo_hardware_chipset[restrict static 1], |
| 3235 | const struct cpuinfo_arm_chipset ro_product_board_chipset[restrict static 1], |
| 3236 | const struct cpuinfo_arm_chipset ro_board_platform_chipset[restrict static 1], |
| 3237 | const struct cpuinfo_arm_chipset ro_chipname_chipset[restrict static 1]) |
| 3238 | { |
| 3239 | if (ro_chipname_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3240 | return *ro_chipname_chipset; |
| 3241 | } |
| 3242 | if (ro_product_board_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3243 | return *ro_product_board_chipset; |
| 3244 | } |
| 3245 | if (proc_cpuinfo_hardware_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3246 | return *proc_cpuinfo_hardware_chipset; |
| 3247 | } |
| 3248 | return *ro_board_platform_chipset; |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 3249 | } |
| 3250 | |
| 3251 | /* |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame^] | 3252 | * Decodes chipset name from Android system properties: |
| 3253 | * - /proc/cpuinfo Hardware string |
| 3254 | * - ro.product.board |
| 3255 | * - ro.board.platform |
| 3256 | * - ro.mediatek.platform |
| 3257 | * - ro.chipname |
| 3258 | * For some chipsets, the function relies frequency and on number of cores for chipset detection. |
| 3259 | * |
| 3260 | * @param[in] properties - structure with the Android system properties described above. |
| 3261 | * @param cores - number of cores in the chipset. |
| 3262 | * @param max_cpu_freq_max - maximum of /sys/devices/system/cpu/cpu<number>/cpofreq/cpu_freq_max values. |
| 3263 | * |
| 3264 | * @returns Decoded chipset name. If chipset could not be decoded, the resulting structure would use `unknown` vendor |
| 3265 | * and series identifiers. |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 3266 | */ |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame^] | 3267 | struct cpuinfo_arm_chipset cpuinfo_arm_android_decode_chipset( |
| 3268 | const struct cpuinfo_android_properties properties[restrict static 1], |
| 3269 | uint32_t cores, |
| 3270 | uint32_t max_cpu_freq_max) |
| 3271 | { |
| 3272 | struct cpuinfo_arm_chipset chipset = { |
| 3273 | .vendor = cpuinfo_arm_chipset_vendor_unknown, |
| 3274 | .series = cpuinfo_arm_chipset_series_unknown, |
| 3275 | }; |
| 3276 | |
| 3277 | const bool tegra_platform = is_tegra( |
| 3278 | properties->ro_board_platform, |
| 3279 | properties->ro_board_platform + strnlen(properties->ro_board_platform, CPUINFO_BUILD_PROP_VALUE_MAX)); |
| 3280 | |
| 3281 | struct cpuinfo_arm_chipset chipsets[cpuinfo_android_chipset_property_max] = { |
| 3282 | [cpuinfo_android_chipset_property_proc_cpuinfo_hardware] = |
| 3283 | cpuinfo_arm_android_decode_chipset_from_proc_cpuinfo_hardware( |
| 3284 | properties->proc_cpuinfo_hardware, cores, max_cpu_freq_max, tegra_platform), |
| 3285 | [cpuinfo_android_chipset_property_ro_product_board] = |
| 3286 | cpuinfo_arm_android_decode_chipset_from_ro_product_board( |
| 3287 | properties->ro_product_board, cores, max_cpu_freq_max), |
| 3288 | [cpuinfo_android_chipset_property_ro_board_platform] = |
| 3289 | cpuinfo_arm_android_decode_chipset_from_ro_board_platform( |
| 3290 | properties->ro_board_platform, cores, max_cpu_freq_max), |
| 3291 | [cpuinfo_android_chipset_property_ro_mediatek_platform] = |
| 3292 | cpuinfo_arm_android_decode_chipset_from_ro_mediatek_platform(properties->ro_mediatek_platform), |
| 3293 | [cpuinfo_android_chipset_property_ro_chipname] = |
| 3294 | cpuinfo_arm_android_decode_chipset_from_ro_chipname(properties->ro_chipname), |
| 3295 | }; |
| 3296 | enum cpuinfo_arm_chipset_vendor vendor = cpuinfo_arm_chipset_vendor_unknown; |
| 3297 | for (size_t i = 0; i < cpuinfo_android_chipset_property_max; i++) { |
| 3298 | const enum cpuinfo_arm_chipset_vendor decoded_vendor = chipsets[i].vendor; |
| 3299 | if (decoded_vendor != cpuinfo_arm_chipset_vendor_unknown) { |
| 3300 | if (vendor == cpuinfo_arm_chipset_vendor_unknown) { |
| 3301 | vendor = decoded_vendor; |
| 3302 | } else if (vendor != decoded_vendor) { |
| 3303 | /* Parsing different system properties produces different chipset vendors. This situation is rare. */ |
| 3304 | cpuinfo_log_error( |
| 3305 | "chipset detection failed: different chipset vendors reported in different system properties"); |
| 3306 | goto finish; |
| 3307 | } |
| 3308 | } |
| 3309 | } |
| 3310 | if (vendor == cpuinfo_arm_chipset_vendor_unknown) { |
| 3311 | cpuinfo_log_warning( |
| 3312 | "chipset detection failed: none of the system properties matched known signatures"); |
| 3313 | goto finish; |
| 3314 | } |
| 3315 | |
| 3316 | /* Fix common bugs in reported chipsets */ |
| 3317 | for (size_t i = 0; i < cpuinfo_android_chipset_property_max; i++) { |
| 3318 | cpuinfo_arm_fixup_chipset(&chipsets[i], cores, max_cpu_freq_max); |
| 3319 | } |
| 3320 | |
| 3321 | /* |
| 3322 | * Propagate suffixes: consider all pairs of chipsets, if both chipsets in the pair are from the same series, |
| 3323 | * and one's suffix is a prefix of another's chipset suffix, use the longest suffix. |
| 3324 | */ |
| 3325 | for (size_t i = 0; i < cpuinfo_android_chipset_property_max; i++) { |
| 3326 | const size_t chipset_i_suffix_length = strnlen(chipsets[i].suffix, CPUINFO_ARM_CHIPSET_SUFFIX_MAX); |
| 3327 | for (size_t j = 0; j < i; j++) { |
| 3328 | if (chipsets[i].series == chipsets[j].series) { |
| 3329 | const size_t chipset_j_suffix_length = strnlen(chipsets[j].suffix, CPUINFO_ARM_CHIPSET_SUFFIX_MAX); |
| 3330 | if (chipset_i_suffix_length != chipset_j_suffix_length) { |
| 3331 | const size_t common_prefix_length = (chipset_i_suffix_length < chipset_j_suffix_length) ? |
| 3332 | chipset_i_suffix_length : chipset_j_suffix_length; |
| 3333 | if (common_prefix_length == 0 || |
| 3334 | memcmp(chipsets[i].suffix, chipsets[j].suffix, common_prefix_length) == 0) |
| 3335 | { |
| 3336 | if (chipset_i_suffix_length > chipset_j_suffix_length) { |
| 3337 | memcpy(chipsets[j].suffix, chipsets[i].suffix, chipset_i_suffix_length); |
| 3338 | } else { |
| 3339 | memcpy(chipsets[i].suffix, chipsets[j].suffix, chipset_j_suffix_length); |
| 3340 | } |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 3341 | } |
| 3342 | } |
| 3343 | } |
| 3344 | } |
| 3345 | } |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 3346 | |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame^] | 3347 | for (size_t i = 0; i < cpuinfo_android_chipset_property_max; i++) { |
| 3348 | if (chipsets[i].series != cpuinfo_arm_chipset_series_unknown) { |
| 3349 | if (chipset.series == cpuinfo_arm_chipset_series_unknown) { |
| 3350 | chipset = chipsets[i]; |
| 3351 | } else if (chipsets[i].series != chipset.series || chipsets[i].model != chipset.model || |
| 3352 | strncmp(chipsets[i].suffix, chipset.suffix, CPUINFO_ARM_CHIPSET_SUFFIX_MAX) != 0) |
| 3353 | { |
| 3354 | cpuinfo_log_info( |
| 3355 | "different chipsets reported in different system properties; " |
| 3356 | "vendor-specific disambiguation heuristic would be used"); |
| 3357 | switch (vendor) { |
| 3358 | case cpuinfo_arm_chipset_vendor_qualcomm: |
| 3359 | return disambiguate_qualcomm_chipset( |
| 3360 | &chipsets[cpuinfo_android_chipset_property_proc_cpuinfo_hardware], |
| 3361 | &chipsets[cpuinfo_android_chipset_property_ro_product_board], |
| 3362 | &chipsets[cpuinfo_android_chipset_property_ro_board_platform], |
| 3363 | &chipsets[cpuinfo_android_chipset_property_ro_chipname]); |
| 3364 | case cpuinfo_arm_chipset_vendor_mediatek: |
| 3365 | return disambiguate_mediatek_chipset( |
| 3366 | &chipsets[cpuinfo_android_chipset_property_proc_cpuinfo_hardware], |
| 3367 | &chipsets[cpuinfo_android_chipset_property_ro_product_board], |
| 3368 | &chipsets[cpuinfo_android_chipset_property_ro_board_platform], |
| 3369 | &chipsets[cpuinfo_android_chipset_property_ro_mediatek_platform], |
| 3370 | &chipsets[cpuinfo_android_chipset_property_ro_chipname]); |
| 3371 | case cpuinfo_arm_chipset_vendor_hisilicon: |
| 3372 | return disambiguate_hisilicon_chipset( |
| 3373 | &chipsets[cpuinfo_android_chipset_property_proc_cpuinfo_hardware], |
| 3374 | &chipsets[cpuinfo_android_chipset_property_ro_product_board], |
| 3375 | &chipsets[cpuinfo_android_chipset_property_ro_board_platform]); |
| 3376 | case cpuinfo_arm_chipset_vendor_amlogic: |
| 3377 | return disambiguate_amlogic_chipset( |
| 3378 | &chipsets[cpuinfo_android_chipset_property_proc_cpuinfo_hardware], |
| 3379 | &chipsets[cpuinfo_android_chipset_property_ro_board_platform]); |
| 3380 | case cpuinfo_arm_chipset_vendor_marvell: |
| 3381 | return disambiguate_marvell_chipset( |
| 3382 | &chipsets[cpuinfo_android_chipset_property_proc_cpuinfo_hardware], |
| 3383 | &chipsets[cpuinfo_android_chipset_property_ro_product_board], |
| 3384 | &chipsets[cpuinfo_android_chipset_property_ro_chipname]); |
| 3385 | case cpuinfo_arm_chipset_vendor_rockchip: |
| 3386 | return disambiguate_rockchip_chipset( |
| 3387 | &chipsets[cpuinfo_android_chipset_property_proc_cpuinfo_hardware], |
| 3388 | &chipsets[cpuinfo_android_chipset_property_ro_product_board], |
| 3389 | &chipsets[cpuinfo_android_chipset_property_ro_board_platform]); |
| 3390 | case cpuinfo_arm_chipset_vendor_spreadtrum: |
| 3391 | return disambiguate_spreadtrum_chipset( |
| 3392 | &chipsets[cpuinfo_android_chipset_property_proc_cpuinfo_hardware], |
| 3393 | &chipsets[cpuinfo_android_chipset_property_ro_product_board], |
| 3394 | &chipsets[cpuinfo_android_chipset_property_ro_board_platform], |
| 3395 | &chipsets[cpuinfo_android_chipset_property_ro_chipname]); |
| 3396 | default: |
| 3397 | cpuinfo_log_error( |
| 3398 | "chipset detection failed: " |
| 3399 | "could not disambiguate different chipsets reported in different system properties"); |
| 3400 | /* chipset variable contains valid, but inconsistent chipset information, overwrite it */ |
| 3401 | chipset = (struct cpuinfo_arm_chipset) { |
| 3402 | .vendor = cpuinfo_arm_chipset_vendor_unknown, |
| 3403 | .series = cpuinfo_arm_chipset_series_unknown, |
| 3404 | }; |
| 3405 | goto finish; |
| 3406 | } |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 3407 | } |
| 3408 | } |
| 3409 | } |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame^] | 3410 | |
| 3411 | finish: |
| 3412 | return chipset; |
| 3413 | } |
| 3414 | #else /* !defined(__ANDROID__) */ |
| 3415 | |
| 3416 | /* |
| 3417 | * Decodes chipset name from /proc/cpuinfo Hardware string. |
| 3418 | * For some chipsets, the function relies frequency and on number of cores for chipset detection. |
| 3419 | * |
| 3420 | * @param[in] hardware - /proc/cpuinfo Hardware string. |
| 3421 | * @param cores - number of cores in the chipset. |
| 3422 | * @param max_cpu_freq_max - maximum of /sys/devices/system/cpu/cpu<number>/cpofreq/cpu_freq_max values. |
| 3423 | * |
| 3424 | * @returns Decoded chipset name. If chipset could not be decoded, the resulting structure would use `unknown` vendor |
| 3425 | * and series identifiers. |
| 3426 | */ |
| 3427 | struct cpuinfo_arm_chipset cpuinfo_arm_linux_decode_chipset( |
| 3428 | const char hardware[restrict static CPUINFO_HARDWARE_VALUE_MAX], |
| 3429 | uint32_t cores, |
| 3430 | uint32_t max_cpu_freq_max) |
| 3431 | { |
| 3432 | struct cpuinfo_arm_chipset chipset = |
| 3433 | cpuinfo_arm_android_decode_chipset_from_proc_cpuinfo_hardware( |
| 3434 | hardware, cores, max_cpu_freq_max, false); |
| 3435 | if (chipset.vendor == cpuinfo_arm_chipset_vendor_unknown) { |
| 3436 | cpuinfo_log_warning( |
| 3437 | "chipset detection failed: /proc/cpuinfo Hardware string did not match known signatures"); |
| 3438 | } else { |
| 3439 | cpuinfo_arm_fixup_chipset(&chipset, cores, max_cpu_freq_max); |
| 3440 | } |
| 3441 | return chipset; |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 3442 | } |
| 3443 | |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame^] | 3444 | #endif |