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