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 */ |
Marat Dukhan | ec133e7 | 2018-03-08 09:49:24 -0800 | [diff] [blame] | 306 | return false; |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 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 | }; |
Marat Dukhan | ec133e7 | 2018-03-08 09:49:24 -0800 | [diff] [blame] | 317 | return true; |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 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 */ |
Marat Dukhan | ec133e7 | 2018-03-08 09:49:24 -0800 | [diff] [blame] | 651 | return false; |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 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 */ |
Marat Dukhan | ec133e7 | 2018-03-08 09:49:24 -0800 | [diff] [blame] | 708 | return false; |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 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 | { |
Marat Dukhan | f3f39f1 | 2017-12-11 13:32:05 +0900 | [diff] [blame] | 1355 | /* "ALP" -> Kirin 970 */ |
| 1356 | .platform = UINT32_C(0x00504C41), /* "\0PLA" = reverse("ALP\0") */ |
| 1357 | .model = 970, |
| 1358 | }, |
| 1359 | { |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1360 | /* "BAC" -> Kirin 659 */ |
| 1361 | .platform = UINT32_C(0x00434142), /* "\0CAB" = reverse("BAC\0") */ |
| 1362 | .model = 659, |
| 1363 | }, |
| 1364 | { |
Marat Dukhan | f3f39f1 | 2017-12-11 13:32:05 +0900 | [diff] [blame] | 1365 | /* "BLA" -> Kirin 970 */ |
| 1366 | .platform = UINT32_C(0x00414C42), /* "\0ALB" = reverse("BLA\0") */ |
| 1367 | .model = 970, |
| 1368 | }, |
| 1369 | { |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1370 | /* "DUK" -> Kirin 960 */ |
| 1371 | .platform = UINT32_C(0x004B5544), /* "\0KUD" = reverse("DUK\0") */ |
| 1372 | .model = 960, |
| 1373 | }, |
| 1374 | { |
| 1375 | /* "EVA" -> Kirin 955 */ |
| 1376 | .platform = UINT32_C(0x00415645), /* "\0AVE" = reverse("EVA\0") */ |
| 1377 | .model = 955, |
| 1378 | }, |
| 1379 | { |
| 1380 | /* "FRD" -> Kirin 950 */ |
| 1381 | .platform = UINT32_C(0x00445246), /* "\0DRF" = reverse("FRD\0") */ |
| 1382 | .model = 950, |
| 1383 | }, |
| 1384 | { |
| 1385 | /* "KNT" -> Kirin 950 */ |
| 1386 | .platform = UINT32_C(0x00544E4B), /* "\0TNK" = reverse("KNT\0") */ |
| 1387 | .model = 950, |
| 1388 | }, |
| 1389 | { |
| 1390 | /* "LON" -> Kirin 960 */ |
| 1391 | .platform = UINT32_C(0x004E4F4C), /* "\0NOL" = reverse("LON\0") */ |
| 1392 | .model = 960, |
| 1393 | }, |
| 1394 | { |
| 1395 | /* "MHA" -> Kirin 960 */ |
| 1396 | .platform = UINT32_C(0x0041484D), /* "\0AHM" = reverse("MHA\0") */ |
| 1397 | .model = 960, |
| 1398 | }, |
| 1399 | { |
| 1400 | /* "NXT" -> Kirin 950 */ |
| 1401 | .platform = UINT32_C(0x0054584E), /* "\0TXN" = reverse("NXT\0") */ |
| 1402 | .model = 950, |
| 1403 | }, |
| 1404 | { |
| 1405 | /* "STF" -> Kirin 960 */ |
| 1406 | .platform = UINT32_C(0x00465453), /* "\0FTS" = reverse("STF\0") */ |
| 1407 | .model = 960, |
| 1408 | }, |
| 1409 | { |
| 1410 | /* "VIE" -> Kirin 955 */ |
| 1411 | .platform = UINT32_C(0x00454956), /* "\0EIV" = reverse("VIE\0") */ |
| 1412 | .model = 955, |
| 1413 | }, |
| 1414 | { |
| 1415 | /* "VKY" -> Kirin 960 */ |
| 1416 | .platform = UINT32_C(0x00594B56), /* "\0YKV" = reverse("VKY\0") */ |
| 1417 | .model = 960, |
| 1418 | }, |
| 1419 | { |
| 1420 | /* "VTR" -> Kirin 960 */ |
| 1421 | .platform = UINT32_C(0x00525456), /* "\0RTV" = reverse("VTR\0") */ |
| 1422 | .model = 960, |
| 1423 | }, |
| 1424 | }; |
| 1425 | |
| 1426 | /** |
| 1427 | * Tries to match ro.product.board string to Huawei /([A-Z]{3})(\-[A-Z]?L\d{2})$/ signature where \1 is one of the |
| 1428 | * known values for Huawei devices, which do not report chipset name elsewhere. |
| 1429 | * If the string matches signature, the function decodes chipset (always HiSilicon Kirin for matched devices) from |
Marat Dukhan | f3f39f1 | 2017-12-11 13:32:05 +0900 | [diff] [blame] | 1430 | * the Huawei platform ID in the signature and stores it in \p chipset argument. |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1431 | * |
| 1432 | * @param start - start of the ro.product.board string to match. |
| 1433 | * @param end - end of the ro.product.board string to match. |
| 1434 | * @param[out] chipset - location where chipset information will be stored upon a successful match and decoding. |
| 1435 | * |
| 1436 | * @returns true if signature matched, false otherwise. |
| 1437 | */ |
| 1438 | static bool match_and_parse_huawei( |
| 1439 | const char* start, const char* end, |
| 1440 | struct cpuinfo_arm_chipset chipset[restrict static 1]) |
| 1441 | { |
| 1442 | /* |
| 1443 | * Expect length of either 3, 7 or 8, exactly: |
| 1444 | * - 3-letter platform identifier (see huawei_platform_map) |
| 1445 | * - 3-letter platform identifier + '-' + 'L' + two digits |
| 1446 | * - 3-letter platform identifier + '-' + capital letter + 'L' + two digits |
| 1447 | */ |
| 1448 | const size_t length = end - start; |
| 1449 | switch (length) { |
| 1450 | case 3: |
| 1451 | case 7: |
| 1452 | case 8: |
| 1453 | break; |
| 1454 | default: |
| 1455 | return false; |
| 1456 | } |
| 1457 | |
| 1458 | /* |
| 1459 | * Try to find the first three-letter substring in among the tabulated entries for Huawei devices. |
| 1460 | * The first three letters are loaded and compared as a little-endian 24-bit word. |
| 1461 | */ |
| 1462 | uint32_t model = 0; |
| 1463 | const uint32_t target_platform_id = load_u24le(start); |
| 1464 | for (uint32_t i = 0; i < CPUINFO_COUNT_OF(huawei_platform_map); i++) { |
| 1465 | if (huawei_platform_map[i].platform == target_platform_id) { |
| 1466 | model = huawei_platform_map[i].model; |
| 1467 | break; |
| 1468 | } |
| 1469 | } |
| 1470 | |
| 1471 | if (model == 0) { |
| 1472 | /* Platform does not match the tabulated Huawei entries */ |
| 1473 | return false; |
| 1474 | } |
| 1475 | |
| 1476 | if (length > 3) { |
| 1477 | /* |
| 1478 | * Check that: |
| 1479 | * - The symbol after platform id is a dash |
| 1480 | * - The symbol after it is an uppercase letter. For 7-symbol strings, the symbol is just 'L'. |
| 1481 | */ |
| 1482 | if (start[3] != '-' || !is_ascii_alphabetic_uppercase(start[4])) { |
| 1483 | return false; |
| 1484 | } |
| 1485 | |
| 1486 | /* Check that the last 3 entries are /L\d\d/ */ |
| 1487 | if (end[-3] != 'L' || !is_ascii_numeric(end[-2]) || !is_ascii_numeric(end[-1])) { |
| 1488 | return false; |
| 1489 | } |
| 1490 | } |
| 1491 | |
| 1492 | /* All checks succeeded, commit chipset name */ |
| 1493 | *chipset = (struct cpuinfo_arm_chipset) { |
| 1494 | .vendor = cpuinfo_arm_chipset_vendor_hisilicon, |
| 1495 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 1496 | .model = model, |
| 1497 | }; |
| 1498 | return true; |
| 1499 | } |
| 1500 | |
| 1501 | /** |
| 1502 | * Tries to match /tcc\d{3}x$/ signature for Telechips TCCXXXx chipsets. |
| 1503 | * If match successful, extracts model information into \p chipset argument. |
| 1504 | * |
| 1505 | * @param start - start of the /proc/cpuinfo Hardware string to match. |
| 1506 | * @param end - end of the /proc/cpuinfo Hardware string to match. |
| 1507 | * @param[out] chipset - location where chipset information will be stored upon a successful match. |
| 1508 | * |
| 1509 | * @returns true if signature matched, false otherwise. |
| 1510 | */ |
| 1511 | static bool match_tcc( |
| 1512 | const char* start, const char* end, |
| 1513 | struct cpuinfo_arm_chipset chipset[restrict static 1]) |
| 1514 | { |
| 1515 | /* Expect exactly 7 symbols: "tcc" (3 symbols) + 3-digit model number + fixed "x" suffix */ |
| 1516 | if (start + 7 != end) { |
| 1517 | return false; |
| 1518 | } |
| 1519 | |
| 1520 | /* Quick check for the first character */ |
| 1521 | if (start[0] != 't') { |
| 1522 | return false; |
| 1523 | } |
| 1524 | |
| 1525 | /* Load the next 2 bytes as little endian 16-bit word */ |
| 1526 | const uint16_t expected_cc = load_u16le(start + 1); |
| 1527 | if (expected_cc != UINT16_C(0x6363) /* "cc" */ ) { |
| 1528 | return false; |
| 1529 | } |
| 1530 | |
| 1531 | /* Check and parse 3-digit model number */ |
| 1532 | uint32_t model = 0; |
| 1533 | for (uint32_t i = 3; i < 6; i++) { |
| 1534 | const uint32_t digit = (uint32_t) (uint8_t) start[i] - '0'; |
| 1535 | if (digit >= 10) { |
| 1536 | /* Not really a digit */ |
| 1537 | return false; |
| 1538 | } |
| 1539 | model = model * 10 + digit; |
| 1540 | } |
| 1541 | |
| 1542 | /* Check the fixed 'x' suffix in the end */ |
| 1543 | if (start[6] != 'x') { |
| 1544 | return false; |
| 1545 | } |
| 1546 | |
| 1547 | /* Commit parsed chipset. */ |
| 1548 | *chipset = (struct cpuinfo_arm_chipset) { |
| 1549 | .vendor = cpuinfo_arm_chipset_vendor_telechips, |
| 1550 | .series = cpuinfo_arm_chipset_series_telechips_tcc, |
| 1551 | .model = model, |
Marat Dukhan | 63a6a10 | 2017-08-24 21:28:02 -0700 | [diff] [blame] | 1552 | .suffix = { |
| 1553 | [0] = 'X' |
| 1554 | }, |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1555 | }; |
| 1556 | return true; |
| 1557 | } |
| 1558 | |
| 1559 | /* |
Marat Dukhan | 93982f2 | 2017-10-20 13:10:23 -0700 | [diff] [blame] | 1560 | * Compares ro.board.platform string to Nvidia Tegra signatures ("tegra" and "tegra3") |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1561 | * This check has effect on how /proc/cpuinfo Hardware string is interpreted. |
| 1562 | * |
| 1563 | * @param start - start of the ro.board.platform string to check. |
| 1564 | * @param end - end of the ro.board.platform string to check. |
| 1565 | * |
Marat Dukhan | 93982f2 | 2017-10-20 13:10:23 -0700 | [diff] [blame] | 1566 | * @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] | 1567 | */ |
| 1568 | static bool is_tegra(const char* start, const char* end) { |
| 1569 | /* Expect 5 ("tegra") or 6 ("tegra3") symbols */ |
| 1570 | const size_t length = end - start; |
| 1571 | switch (length) { |
| 1572 | case 5: |
| 1573 | case 6: |
| 1574 | break; |
| 1575 | default: |
| 1576 | return false; |
| 1577 | } |
| 1578 | |
| 1579 | /* Check that the first 5 characters match "tegra" */ |
| 1580 | if (start[0] != 't') { |
| 1581 | return false; |
| 1582 | } |
| 1583 | const uint32_t expected_egra = load_u32le(start + 1); |
| 1584 | if (expected_egra != UINT32_C(0x61726765) /* "arge" = reverse("egra") */) { |
| 1585 | return false; |
| 1586 | } |
| 1587 | |
| 1588 | /* Check if the string is either "tegra" (length = 5) or "tegra3" (length != 5) and last character is '3' */ |
| 1589 | return (length == 5 || start[5] == '3'); |
| 1590 | } |
| 1591 | |
| 1592 | struct special_map_entry { |
| 1593 | const char* platform; |
| 1594 | uint16_t model; |
| 1595 | uint8_t series; |
| 1596 | char suffix; |
| 1597 | }; |
| 1598 | |
| 1599 | static const struct special_map_entry special_hardware_map_entries[] = { |
| 1600 | { |
| 1601 | /* "k3v2oem1" -> HiSilicon K3V2 */ |
| 1602 | .platform = "k3v2oem1", |
| 1603 | .series = cpuinfo_arm_chipset_series_hisilicon_k3v, |
| 1604 | .model = 2, |
| 1605 | }, |
| 1606 | { |
| 1607 | /* "hi6620oem" -> HiSilicon Kirin 910T */ |
| 1608 | .platform = "hi6620oem", |
| 1609 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 1610 | .model = 910, |
| 1611 | .suffix = 'T' |
| 1612 | }, |
| 1613 | { |
| 1614 | /* "hi6250" -> HiSilicon Kirin 650 */ |
| 1615 | .platform = "hi6250", |
| 1616 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 1617 | .model = 650, |
| 1618 | }, |
| 1619 | { |
| 1620 | /* "hi6210sft" -> HiSilicon Kirin 620 */ |
| 1621 | .platform = "hi6210sft", |
| 1622 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 1623 | .model = 620, |
| 1624 | }, |
| 1625 | { |
| 1626 | /* "hi3751" -> HiSilicon Hi3751 */ |
| 1627 | .platform = "hi3751", |
| 1628 | .series = cpuinfo_arm_chipset_series_hisilicon_hi, |
| 1629 | .model = 3751, |
| 1630 | }, |
| 1631 | { |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1632 | /* "hi3630" -> HiSilicon Kirin 920 */ |
| 1633 | .platform = "hi3630", |
| 1634 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 1635 | .model = 920, |
| 1636 | }, |
| 1637 | { |
Marat Dukhan | f3f39f1 | 2017-12-11 13:32:05 +0900 | [diff] [blame] | 1638 | /* "hi3635" -> HiSilicon Kirin 930 */ |
| 1639 | .platform = "hi3635", |
| 1640 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 1641 | .model = 930, |
| 1642 | }, |
| 1643 | { |
Marat Dukhan | 2340188 | 2017-11-28 11:07:46 -0800 | [diff] [blame] | 1644 | /* "gs702a" -> Actions ATM7029 (Cortex-A5 + GC1000) */ |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1645 | .platform = "gs702a", |
| 1646 | .series = cpuinfo_arm_chipset_series_actions_atm, |
| 1647 | .model = 7029, |
| 1648 | }, |
| 1649 | { |
Marat Dukhan | 2340188 | 2017-11-28 11:07:46 -0800 | [diff] [blame] | 1650 | /* "gs702c" -> Actions ATM7029B (Cortex-A5 + SGX540) */ |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1651 | .platform = "gs702c", |
| 1652 | .series = cpuinfo_arm_chipset_series_actions_atm, |
| 1653 | .model = 7029, |
Marat Dukhan | 2340188 | 2017-11-28 11:07:46 -0800 | [diff] [blame] | 1654 | .suffix = 'B', |
| 1655 | }, |
| 1656 | { |
Marat Dukhan | 9c34544 | 2017-11-29 17:41:13 -0800 | [diff] [blame] | 1657 | /* "gs703d" -> Actions ATM7039S */ |
Marat Dukhan | 2340188 | 2017-11-28 11:07:46 -0800 | [diff] [blame] | 1658 | .platform = "gs703d", |
| 1659 | .series = cpuinfo_arm_chipset_series_actions_atm, |
| 1660 | .model = 7039, |
| 1661 | .suffix = 'S', |
| 1662 | }, |
| 1663 | { |
| 1664 | /* "gs705a" -> Actions ATM7059A */ |
| 1665 | .platform = "gs705a", |
| 1666 | .series = cpuinfo_arm_chipset_series_actions_atm, |
| 1667 | .model = 7059, |
| 1668 | .suffix = 'A', |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1669 | }, |
| 1670 | { |
| 1671 | /* "Amlogic Meson8" -> Amlogic S812 */ |
| 1672 | .platform = "Amlogic Meson8", |
| 1673 | .series = cpuinfo_arm_chipset_series_amlogic_s, |
| 1674 | .model = 812, |
| 1675 | }, |
| 1676 | { |
| 1677 | /* "Amlogic Meson8B" -> Amlogic S805 */ |
| 1678 | .platform = "Amlogic Meson8B", |
| 1679 | .series = cpuinfo_arm_chipset_series_amlogic_s, |
| 1680 | .model = 805, |
| 1681 | }, |
| 1682 | { |
| 1683 | /* "mapphone_CDMA" -> Texas Instruments OMAP4430 */ |
| 1684 | .platform = "mapphone_CDMA", |
| 1685 | .series = cpuinfo_arm_chipset_series_texas_instruments_omap, |
| 1686 | .model = 4430, |
| 1687 | }, |
| 1688 | { |
Marat Dukhan | dd698c7 | 2017-12-15 11:24:53 -0800 | [diff] [blame] | 1689 | /* "Superior" -> Texas Instruments OMAP4470 */ |
| 1690 | .platform = "Superior", |
| 1691 | .series = cpuinfo_arm_chipset_series_texas_instruments_omap, |
| 1692 | .model = 4470, |
| 1693 | }, |
| 1694 | { |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1695 | /* "Tuna" (Samsung Galaxy Nexus) -> Texas Instruments OMAP4460 */ |
| 1696 | .platform = "Tuna", |
| 1697 | .series = cpuinfo_arm_chipset_series_texas_instruments_omap, |
| 1698 | .model = 4460, |
| 1699 | }, |
| 1700 | { |
| 1701 | /* "Manta" (Samsung Nexus 10) -> Samsung Exynos 5250 */ |
| 1702 | .platform = "Manta", |
| 1703 | .series = cpuinfo_arm_chipset_series_samsung_exynos, |
| 1704 | .model = 5250, |
| 1705 | }, |
| 1706 | { |
| 1707 | /* "Odin" -> LG Nuclun 7111 */ |
| 1708 | .platform = "Odin", |
| 1709 | .series = cpuinfo_arm_chipset_series_lg_nuclun, |
| 1710 | .model = 7111, |
| 1711 | }, |
| 1712 | { |
| 1713 | /* "Madison" -> MStar 6A338 */ |
| 1714 | .platform = "Madison", |
| 1715 | .series = cpuinfo_arm_chipset_series_mstar_6a, |
| 1716 | .model = 338, |
| 1717 | }, |
| 1718 | }; |
| 1719 | |
| 1720 | static const struct special_map_entry tegra_hardware_map_entries[] = { |
| 1721 | { |
Marat Dukhan | 93982f2 | 2017-10-20 13:10:23 -0700 | [diff] [blame] | 1722 | /* "cardhu" (Nvidia Cardhu developer tablet) -> Tegra T30 */ |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1723 | .platform = "cardhu", |
| 1724 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1725 | .model = 30, |
| 1726 | }, |
| 1727 | { |
Marat Dukhan | 56b2403 | 2017-09-05 18:40:20 -0700 | [diff] [blame] | 1728 | /* "kai" -> Tegra T30L */ |
| 1729 | .platform = "kai", |
| 1730 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1731 | .model = 30, |
| 1732 | .suffix = 'L', |
| 1733 | }, |
| 1734 | { |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1735 | /* "p3" (Samsung Galaxy Tab 8.9) -> Tegra T20 */ |
| 1736 | .platform = "p3", |
| 1737 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1738 | .model = 20, |
| 1739 | }, |
| 1740 | { |
Marat Dukhan | 56b2403 | 2017-09-05 18:40:20 -0700 | [diff] [blame] | 1741 | /* "n1" (Samsung Galaxy R / Samsung Captivate Glide) -> Tegra AP20H */ |
| 1742 | .platform = "n1", |
| 1743 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_ap, |
| 1744 | .model = 20, |
| 1745 | .suffix = 'H', |
| 1746 | }, |
| 1747 | { |
| 1748 | /* "SHW-M380S" (Samsung Galaxy Tab 10.1) -> Tegra T20 */ |
| 1749 | .platform = "SHW-M380S", |
| 1750 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1751 | .model = 20, |
| 1752 | }, |
| 1753 | { |
| 1754 | /* "m470" (Hisense Sero 7 Pro) -> Tegra T30L */ |
| 1755 | .platform = "m470", |
| 1756 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1757 | .model = 30, |
| 1758 | .suffix = 'L', |
| 1759 | }, |
| 1760 | { |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1761 | /* "endeavoru" (HTC One X) -> Tegra AP33 */ |
| 1762 | .platform = "endeavoru", |
| 1763 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_ap, |
| 1764 | .model = 33, |
| 1765 | }, |
| 1766 | { |
| 1767 | /* "evitareul" (HTC One X+) -> Tegra T33 */ |
| 1768 | .platform = "evitareul", |
| 1769 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1770 | .model = 33, |
| 1771 | }, |
| 1772 | { |
| 1773 | /* "enrc2b" (HTC One X+) -> Tegra T33 */ |
| 1774 | .platform = "enrc2b", |
| 1775 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1776 | .model = 33, |
| 1777 | }, |
| 1778 | { |
| 1779 | /* "mozart" (Asus Transformer Pad TF701T) -> Tegra T114 */ |
| 1780 | .platform = "mozart", |
| 1781 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1782 | .model = 114, |
| 1783 | }, |
| 1784 | { |
Marat Dukhan | 56b2403 | 2017-09-05 18:40:20 -0700 | [diff] [blame] | 1785 | /* "tegratab" (Tegra Note 7) -> Tegra T114 */ |
| 1786 | .platform = "tegratab", |
| 1787 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1788 | .model = 114, |
| 1789 | }, |
| 1790 | { |
Marat Dukhan | 93982f2 | 2017-10-20 13:10:23 -0700 | [diff] [blame] | 1791 | /* "tn8" (Nvidia Shield Tablet K1) -> Tegra T124 */ |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1792 | .platform = "tn8", |
| 1793 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1794 | .model = 124, |
| 1795 | }, |
| 1796 | { |
Marat Dukhan | 93982f2 | 2017-10-20 13:10:23 -0700 | [diff] [blame] | 1797 | /* "roth" (Nvidia Shield Portable) -> Tegra T114 */ |
Marat Dukhan | 56b2403 | 2017-09-05 18:40:20 -0700 | [diff] [blame] | 1798 | .platform = "roth", |
| 1799 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1800 | .model = 114, |
| 1801 | }, |
| 1802 | { |
Marat Dukhan | 93982f2 | 2017-10-20 13:10:23 -0700 | [diff] [blame] | 1803 | /* "foster_e" (Nvidia Shield TV, Flash) -> Tegra T210 */ |
Marat Dukhan | 56b2403 | 2017-09-05 18:40:20 -0700 | [diff] [blame] | 1804 | .platform = "foster_e", |
| 1805 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1806 | .model = 210, |
| 1807 | }, |
| 1808 | { |
Marat Dukhan | 93982f2 | 2017-10-20 13:10:23 -0700 | [diff] [blame] | 1809 | /* "foster_e_hdd" (Nvidia Shield TV, HDD) -> Tegra T210 */ |
Marat Dukhan | 56b2403 | 2017-09-05 18:40:20 -0700 | [diff] [blame] | 1810 | .platform = "foster_e_hdd", |
| 1811 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1812 | .model = 210, |
| 1813 | }, |
| 1814 | { |
Marat Dukhan | 93982f2 | 2017-10-20 13:10:23 -0700 | [diff] [blame] | 1815 | /* "darcy" (Nvidia Shield TV 2017) -> Tegra T210 */ |
Marat Dukhan | 56b2403 | 2017-09-05 18:40:20 -0700 | [diff] [blame] | 1816 | .platform = "darcy", |
| 1817 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1818 | .model = 210, |
| 1819 | }, |
| 1820 | { |
| 1821 | /* "pisces" (Xiaomi Mi 3) -> Tegra T114 */ |
| 1822 | .platform = "pisces", |
| 1823 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1824 | .model = 114, |
| 1825 | }, |
| 1826 | { |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1827 | /* "mocha" (Xiaomi Mi Pad) -> Tegra T124 */ |
| 1828 | .platform = "mocha", |
| 1829 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1830 | .model = 124, |
| 1831 | }, |
| 1832 | { |
| 1833 | /* "stingray" (Motorola XOOM) -> Tegra AP20H */ |
| 1834 | .platform = "stingray", |
| 1835 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_ap, |
| 1836 | .model = 20, |
| 1837 | .suffix = 'H', |
| 1838 | }, |
| 1839 | { |
| 1840 | /* "Ceres" (Wiko Highway 4G) -> Tegra SL460N */ |
| 1841 | .platform = "Ceres", |
| 1842 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_sl, |
| 1843 | .model = 460, |
| 1844 | .suffix = 'N', |
| 1845 | }, |
| 1846 | { |
Marat Dukhan | 56b2403 | 2017-09-05 18:40:20 -0700 | [diff] [blame] | 1847 | /* "MT799" (nabi 2 Tablet) -> Tegra T30 */ |
| 1848 | .platform = "MT799", |
| 1849 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1850 | .model = 30, |
| 1851 | }, |
| 1852 | { |
| 1853 | /* "t8400n" (nabi DreamTab HD8) -> Tegra T114 */ |
| 1854 | .platform = "t8400n", |
| 1855 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1856 | .model = 114, |
| 1857 | }, |
| 1858 | { |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1859 | /* "chagall" (Fujitsu Stylistic M532) -> Tegra T30 */ |
| 1860 | .platform = "chagall", |
| 1861 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1862 | .model = 30, |
| 1863 | }, |
| 1864 | { |
| 1865 | /* "ventana" (Asus Transformer TF101) -> Tegra T20 */ |
| 1866 | .platform = "ventana", |
| 1867 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1868 | .model = 20, |
| 1869 | }, |
| 1870 | { |
| 1871 | /* "bobsleigh" (Fujitsu Arrows Tab F-05E) -> Tegra T33 */ |
| 1872 | .platform = "bobsleigh", |
| 1873 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1874 | .model = 33, |
| 1875 | }, |
| 1876 | { |
Marat Dukhan | 56b2403 | 2017-09-05 18:40:20 -0700 | [diff] [blame] | 1877 | /* "tegra_fjdev101" (Fujitsu Arrows X F-10D) -> Tegra AP33 */ |
| 1878 | .platform = "tegra_fjdev101", |
| 1879 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_ap, |
| 1880 | .model = 33, |
| 1881 | }, |
| 1882 | { |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1883 | /* "tegra_fjdev103" (Fujitsu Arrows V F-04E) -> Tegra T33 */ |
| 1884 | .platform = "tegra_fjdev103", |
| 1885 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1886 | .model = 33, |
| 1887 | }, |
| 1888 | { |
| 1889 | /* "nbx03" (Sony Tablet S) -> Tegra T20 */ |
| 1890 | .platform = "nbx03", |
| 1891 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1892 | .model = 20, |
| 1893 | }, |
| 1894 | { |
| 1895 | /* "txs03" (Sony Xperia Tablet S) -> Tegra T30L */ |
| 1896 | .platform = "txs03", |
| 1897 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1898 | .model = 30, |
| 1899 | .suffix = 'L', |
| 1900 | }, |
| 1901 | { |
| 1902 | /* "x3" (LG Optimus 4X HD P880) -> Tegra AP33 */ |
| 1903 | .platform = "x3", |
| 1904 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_ap, |
| 1905 | .model = 33, |
| 1906 | }, |
| 1907 | { |
Marat Dukhan | 56b2403 | 2017-09-05 18:40:20 -0700 | [diff] [blame] | 1908 | /* "vu10" (LG Optimus Vu P895) -> Tegra AP33 */ |
| 1909 | .platform = "vu10", |
| 1910 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_ap, |
| 1911 | .model = 33, |
| 1912 | }, |
| 1913 | { |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1914 | /* "BIRCH" (HP Slate 7 Plus) -> Tegra T30L */ |
| 1915 | .platform = "BIRCH", |
| 1916 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1917 | .model = 30, |
| 1918 | .suffix = 'L', |
| 1919 | }, |
| 1920 | { |
| 1921 | /* "macallan" (HP Slate 8 Pro) -> Tegra T114 */ |
| 1922 | .platform = "macallan", |
| 1923 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1924 | .model = 114, |
| 1925 | }, |
| 1926 | { |
Marat Dukhan | 56b2403 | 2017-09-05 18:40:20 -0700 | [diff] [blame] | 1927 | /* "maya" (HP SlateBook 10 x2) -> Tegra T114 */ |
| 1928 | .platform = "maya", |
| 1929 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1930 | .model = 114, |
| 1931 | }, |
| 1932 | { |
| 1933 | /* "antares" (Toshiba AT100) -> Tegra T20 */ |
| 1934 | .platform = "antares", |
| 1935 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1936 | .model = 20, |
| 1937 | }, |
| 1938 | { |
| 1939 | /* "tostab12AL" (Toshiba AT300SE "Excite 10 SE") -> Tegra T30L */ |
| 1940 | .platform = "tostab12AL", |
| 1941 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1942 | .model = 30, |
| 1943 | .suffix = 'L', |
| 1944 | }, |
| 1945 | { |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1946 | /* "tostab12BL" (Toshiba AT10-A "Excite Pure") -> Tegra T30L */ |
| 1947 | .platform = "tostab12BL", |
| 1948 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1949 | .model = 30, |
| 1950 | .suffix = 'L', |
| 1951 | }, |
| 1952 | { |
Marat Dukhan | 56b2403 | 2017-09-05 18:40:20 -0700 | [diff] [blame] | 1953 | /* "sphinx" (Toshiba AT270 "Excite 7.7") -> Tegra T30 */ |
| 1954 | .platform = "sphinx", |
| 1955 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1956 | .model = 30, |
| 1957 | }, |
| 1958 | { |
| 1959 | /* "tostab11BS" (Toshiba AT570 "Regza 7.7") -> Tegra T30 */ |
| 1960 | .platform = "tostab11BS", |
| 1961 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1962 | .model = 30, |
| 1963 | }, |
| 1964 | { |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1965 | /* "tostab12BA" (Toshiba AT10-LE-A "Excite Pro") -> Tegra T114 */ |
| 1966 | .platform = "tostab12BA", |
| 1967 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1968 | .model = 114, |
| 1969 | }, |
| 1970 | { |
Marat Dukhan | 56b2403 | 2017-09-05 18:40:20 -0700 | [diff] [blame] | 1971 | /* "vangogh" (Acer Iconia Tab A100) -> Tegra T20 */ |
| 1972 | .platform = "vangogh", |
| 1973 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1974 | .model = 20, |
Marat Dukhan | 56b2403 | 2017-09-05 18:40:20 -0700 | [diff] [blame] | 1975 | }, |
| 1976 | { |
| 1977 | /* "a110" (Acer Iconia Tab A110) -> Tegra T30L */ |
| 1978 | .platform = "a110", |
| 1979 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1980 | .model = 30, |
| 1981 | .suffix = 'L', |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1982 | }, |
| 1983 | { |
| 1984 | /* "picasso_e" (Acer Iconia Tab A200) -> Tegra AP20H */ |
| 1985 | .platform = "picasso_e", |
| 1986 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_ap, |
| 1987 | .model = 20, |
| 1988 | .suffix = 'H', |
| 1989 | }, |
| 1990 | { |
| 1991 | /* "picasso_e2" (Acer Iconia Tab A210) -> Tegra T30L */ |
| 1992 | .platform = "picasso_e2", |
| 1993 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 1994 | .model = 30, |
| 1995 | .suffix = 'L', |
| 1996 | }, |
| 1997 | { |
Marat Dukhan | 56b2403 | 2017-09-05 18:40:20 -0700 | [diff] [blame] | 1998 | /* "picasso" (Acer Iconia Tab A500) -> Tegra AP20H */ |
| 1999 | .platform = "picasso", |
| 2000 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_ap, |
| 2001 | .model = 20, |
| 2002 | .suffix = 'H', |
| 2003 | }, |
| 2004 | { |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 2005 | /* "picasso_m" (Acer Iconia Tab A510) -> Tegra T30 */ |
| 2006 | .platform = "picasso_m", |
| 2007 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 2008 | .model = 30, |
| 2009 | }, |
| 2010 | { |
| 2011 | /* "picasso_mf" (Acer Iconia Tab A700) -> Tegra T30 */ |
| 2012 | .platform = "picasso_mf", |
| 2013 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 2014 | .model = 30, |
| 2015 | }, |
| 2016 | { |
| 2017 | /* "avalon" (Toshiba AT300 "Excite 10") -> Tegra T30L */ |
| 2018 | .platform = "avalon", |
| 2019 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 2020 | .model = 30, |
| 2021 | .suffix = 'L', |
| 2022 | }, |
| 2023 | { |
| 2024 | /* "NS_14T004" (iRiver NS-14T004) -> Tegra T30L */ |
| 2025 | .platform = "NS_14T004", |
| 2026 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 2027 | .model = 30, |
| 2028 | .suffix = 'L', |
| 2029 | }, |
Marat Dukhan | 56b2403 | 2017-09-05 18:40:20 -0700 | [diff] [blame] | 2030 | { |
| 2031 | /* "WIKIPAD" (Wikipad) -> Tegra T30 */ |
| 2032 | .platform = "WIKIPAD", |
| 2033 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 2034 | .model = 30, |
| 2035 | }, |
| 2036 | { |
| 2037 | /* "kb" (Pegatron Q00Q) -> Tegra T114 */ |
| 2038 | .platform = "kb", |
| 2039 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 2040 | .model = 114, |
| 2041 | }, |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 2042 | }; |
| 2043 | |
| 2044 | /* |
| 2045 | * Decodes chipset name from /proc/cpuinfo Hardware string. |
| 2046 | * For some chipsets, the function relies frequency and on number of cores for chipset detection. |
| 2047 | * |
| 2048 | * @param[in] platform - /proc/cpuinfo Hardware string. |
| 2049 | * @param cores - number of cores in the chipset. |
| 2050 | * @param max_cpu_freq_max - maximum of /sys/devices/system/cpu/cpu<number>/cpofreq/cpu_freq_max values. |
| 2051 | * |
| 2052 | * @returns Decoded chipset name. If chipset could not be decoded, the resulting structure would use `unknown` vendor |
| 2053 | * and series identifiers. |
| 2054 | */ |
Marat Dukhan | 1415d7d | 2017-10-16 09:40:15 -0700 | [diff] [blame] | 2055 | 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] | 2056 | const char hardware[restrict static CPUINFO_HARDWARE_VALUE_MAX], |
| 2057 | uint32_t cores, uint32_t max_cpu_freq_max, bool is_tegra) |
| 2058 | { |
| 2059 | struct cpuinfo_arm_chipset chipset; |
| 2060 | const size_t hardware_length = strnlen(hardware, CPUINFO_HARDWARE_VALUE_MAX); |
| 2061 | const char* hardware_end = hardware + hardware_length; |
| 2062 | |
| 2063 | if (is_tegra) { |
| 2064 | /* |
Marat Dukhan | 93982f2 | 2017-10-20 13:10:23 -0700 | [diff] [blame] | 2065 | * Nvidia Tegra-specific path: compare /proc/cpuinfo Hardware string to |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 2066 | * tabulated Hardware values for popular chipsets/devices with Tegra chipsets. |
| 2067 | * This path is only used when ro.board.platform indicates a Tegra chipset |
| 2068 | * (albeit does not indicate which exactly Tegra chipset). |
| 2069 | */ |
| 2070 | for (size_t i = 0; i < CPUINFO_COUNT_OF(tegra_hardware_map_entries); i++) { |
| 2071 | if (strncmp(tegra_hardware_map_entries[i].platform, hardware, hardware_length) == 0 && |
| 2072 | tegra_hardware_map_entries[i].platform[hardware_length] == 0) |
| 2073 | { |
| 2074 | cpuinfo_log_debug( |
Marat Dukhan | 93982f2 | 2017-10-20 13:10:23 -0700 | [diff] [blame] | 2075 | "found /proc/cpuinfo Hardware string \"%.*s\" in Nvidia Tegra chipset table", |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 2076 | (int) hardware_length, hardware); |
| 2077 | /* Create chipset name from entry */ |
| 2078 | return (struct cpuinfo_arm_chipset) { |
| 2079 | .vendor = chipset_series_vendor[tegra_hardware_map_entries[i].series], |
| 2080 | .series = (enum cpuinfo_arm_chipset_series) tegra_hardware_map_entries[i].series, |
| 2081 | .model = tegra_hardware_map_entries[i].model, |
| 2082 | .suffix = { |
| 2083 | [0] = tegra_hardware_map_entries[i].suffix, |
| 2084 | }, |
| 2085 | }; |
| 2086 | } |
| 2087 | } |
| 2088 | } else { |
| 2089 | /* Generic path: consider all other vendors */ |
| 2090 | |
| 2091 | bool word_start = true; |
| 2092 | for (const char* pos = hardware; pos != hardware_end; pos++) { |
| 2093 | const char c = *pos; |
| 2094 | switch (c) { |
| 2095 | case ' ': |
| 2096 | case '\t': |
| 2097 | case ',': |
| 2098 | word_start = true; |
| 2099 | break; |
| 2100 | default: |
| 2101 | if (word_start && is_ascii_alphabetic(c)) { |
| 2102 | /* Check Qualcomm MSM/APQ signature */ |
| 2103 | if (match_msm_apq(pos, hardware_end, &chipset)) { |
| 2104 | cpuinfo_log_debug( |
| 2105 | "matched Qualcomm MSM/APQ signature in /proc/cpuinfo Hardware string \"%.*s\"", |
| 2106 | (int) hardware_length, hardware); |
| 2107 | return chipset; |
| 2108 | } |
| 2109 | |
| 2110 | /* Check SDMxxx (Qualcomm Snapdragon) signature */ |
| 2111 | if (match_sdm(pos, hardware_end, &chipset)) { |
| 2112 | cpuinfo_log_debug( |
| 2113 | "matched Qualcomm SDM signature in /proc/cpuinfo Hardware string \"%.*s\"", |
| 2114 | (int) hardware_length, hardware); |
| 2115 | return chipset; |
| 2116 | } |
| 2117 | |
| 2118 | /* Check MediaTek MT signature */ |
| 2119 | if (match_mt(pos, hardware_end, true, &chipset)) { |
| 2120 | cpuinfo_log_debug( |
| 2121 | "matched MediaTek MT signature in /proc/cpuinfo Hardware string \"%.*s\"", |
| 2122 | (int) hardware_length, hardware); |
| 2123 | return chipset; |
| 2124 | } |
| 2125 | |
| 2126 | /* Check HiSilicon Kirin signature */ |
| 2127 | if (match_kirin(pos, hardware_end, &chipset)) { |
| 2128 | cpuinfo_log_debug( |
| 2129 | "matched HiSilicon Kirin signature in /proc/cpuinfo Hardware string \"%.*s\"", |
| 2130 | (int) hardware_length, hardware); |
| 2131 | return chipset; |
| 2132 | } |
| 2133 | |
| 2134 | /* Check Rockchip RK signature */ |
| 2135 | if (match_rk(pos, hardware_end, &chipset)) { |
| 2136 | cpuinfo_log_debug( |
| 2137 | "matched Rockchip RK signature in /proc/cpuinfo Hardware string \"%.*s\"", |
| 2138 | (int) hardware_length, hardware); |
| 2139 | return chipset; |
| 2140 | } |
| 2141 | } |
| 2142 | word_start = false; |
| 2143 | break; |
| 2144 | } |
| 2145 | } |
| 2146 | |
| 2147 | /* Check Samsung Exynos signature */ |
| 2148 | if (match_samsung_exynos(hardware, hardware_end, &chipset)) { |
| 2149 | cpuinfo_log_debug( |
| 2150 | "matched Samsung Exynos signature in /proc/cpuinfo Hardware string \"%.*s\"", |
| 2151 | (int) hardware_length, hardware); |
| 2152 | return chipset; |
| 2153 | } |
| 2154 | |
| 2155 | /* Check universalXXXX (Samsung Exynos) signature */ |
| 2156 | if (match_universal(hardware, hardware_end, &chipset)) { |
| 2157 | cpuinfo_log_debug( |
| 2158 | "matched UNIVERSAL (Samsung Exynos) signature in /proc/cpuinfo Hardware string \"%.*s\"", |
| 2159 | (int) hardware_length, hardware); |
| 2160 | return chipset; |
| 2161 | } |
| 2162 | |
| 2163 | /* Match /SMDK(4410|4x12)$/ */ |
| 2164 | if (match_and_parse_smdk(hardware, hardware_end, cores, &chipset)) { |
| 2165 | cpuinfo_log_debug( |
| 2166 | "matched SMDK (Samsung Exynos) signature in /proc/cpuinfo Hardware string \"%.*s\"", |
| 2167 | (int) hardware_length, hardware); |
| 2168 | return chipset; |
| 2169 | } |
| 2170 | |
| 2171 | /* Check Spreadtrum SC signature */ |
| 2172 | if (match_sc(hardware, hardware_end, &chipset)) { |
| 2173 | cpuinfo_log_debug( |
| 2174 | "matched Spreadtrum SC signature in /proc/cpuinfo Hardware string \"%.*s\"", |
| 2175 | (int) hardware_length, hardware); |
| 2176 | return chipset; |
| 2177 | } |
| 2178 | |
| 2179 | /* Check Marvell PXA signature */ |
| 2180 | if (match_pxa(hardware, hardware_end, &chipset)) { |
| 2181 | cpuinfo_log_debug( |
| 2182 | "matched Marvell PXA signature in /proc/cpuinfo Hardware string \"%.*s\"", |
| 2183 | (int) hardware_length, hardware); |
| 2184 | return chipset; |
| 2185 | } |
| 2186 | |
| 2187 | /* Match /sun\d+i/ signature and map to Allwinner chipset name */ |
| 2188 | if (match_and_parse_sunxi(hardware, hardware_end, cores, &chipset)) { |
| 2189 | cpuinfo_log_debug( |
| 2190 | "matched sunxi (Allwinner Ax) signature in /proc/cpuinfo Hardware string \"%.*s\"", |
| 2191 | (int) hardware_length, hardware); |
| 2192 | return chipset; |
| 2193 | } |
| 2194 | |
| 2195 | /* Check Texas Instruments OMAP signature */ |
| 2196 | if (match_omap(hardware, hardware_end, &chipset)) { |
| 2197 | cpuinfo_log_debug( |
| 2198 | "matched Texas Instruments OMAP signature in /proc/cpuinfo Hardware string \"%.*s\"", |
| 2199 | (int) hardware_length, hardware); |
| 2200 | return chipset; |
| 2201 | } |
| 2202 | |
| 2203 | /* Check WonderMedia WMT signature and decode chipset from frequency and number of cores */ |
| 2204 | if (match_and_parse_wmt(hardware, hardware_end, cores, max_cpu_freq_max, &chipset)) { |
| 2205 | cpuinfo_log_debug( |
| 2206 | "matched WonderMedia WMT signature in /proc/cpuinfo Hardware string \"%.*s\"", |
| 2207 | (int) hardware_length, hardware); |
| 2208 | return chipset; |
| 2209 | } |
| 2210 | |
| 2211 | /* Check Telechips TCC signature */ |
| 2212 | if (match_tcc(hardware, hardware_end, &chipset)) { |
| 2213 | cpuinfo_log_debug( |
| 2214 | "matched Telechips TCC signature in /proc/cpuinfo Hardware string \"%.*s\"", |
| 2215 | (int) hardware_length, hardware); |
| 2216 | return chipset; |
| 2217 | } |
| 2218 | |
| 2219 | /* Compare to tabulated Hardware values for popular chipsets/devices which can't be otherwise detected */ |
| 2220 | for (size_t i = 0; i < CPUINFO_COUNT_OF(special_hardware_map_entries); i++) { |
| 2221 | if (strncmp(special_hardware_map_entries[i].platform, hardware, hardware_length) == 0 && |
| 2222 | special_hardware_map_entries[i].platform[hardware_length] == 0) |
| 2223 | { |
| 2224 | cpuinfo_log_debug( |
| 2225 | "found /proc/cpuinfo Hardware string \"%.*s\" in special chipset table", |
| 2226 | (int) hardware_length, hardware); |
| 2227 | /* Create chipset name from entry */ |
| 2228 | return (struct cpuinfo_arm_chipset) { |
| 2229 | .vendor = chipset_series_vendor[special_hardware_map_entries[i].series], |
| 2230 | .series = (enum cpuinfo_arm_chipset_series) special_hardware_map_entries[i].series, |
| 2231 | .model = special_hardware_map_entries[i].model, |
| 2232 | .suffix = { |
| 2233 | [0] = special_hardware_map_entries[i].suffix, |
| 2234 | }, |
| 2235 | }; |
| 2236 | } |
| 2237 | } |
| 2238 | } |
| 2239 | |
| 2240 | return (struct cpuinfo_arm_chipset) { |
| 2241 | .vendor = cpuinfo_arm_chipset_vendor_unknown, |
| 2242 | .series = cpuinfo_arm_chipset_series_unknown, |
| 2243 | }; |
| 2244 | } |
| 2245 | |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 2246 | #ifdef __ANDROID__ |
| 2247 | static const struct special_map_entry special_board_map_entries[] = { |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 2248 | { |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 2249 | /* "hi6250" -> HiSilicon Kirin 650 */ |
| 2250 | .platform = "hi6250", |
| 2251 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2252 | .model = 650, |
| 2253 | }, |
| 2254 | { |
| 2255 | /* "hi6210sft" -> HiSilicon Kirin 620 */ |
| 2256 | .platform = "hi6210sft", |
| 2257 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2258 | .model = 620, |
| 2259 | }, |
| 2260 | { |
Marat Dukhan | f3f39f1 | 2017-12-11 13:32:05 +0900 | [diff] [blame] | 2261 | /* "hi3630" -> HiSilicon Kirin 920 */ |
| 2262 | .platform = "hi3630", |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 2263 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
Marat Dukhan | f3f39f1 | 2017-12-11 13:32:05 +0900 | [diff] [blame] | 2264 | .model = 920, |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 2265 | }, |
| 2266 | { |
| 2267 | /* "hi3635" -> HiSilicon Kirin 930 */ |
| 2268 | .platform = "hi3635", |
| 2269 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2270 | .model = 930, |
| 2271 | }, |
| 2272 | { |
Marat Dukhan | f3f39f1 | 2017-12-11 13:32:05 +0900 | [diff] [blame] | 2273 | /* "hi3650" -> HiSilicon Kirin 950 */ |
| 2274 | .platform = "hi3650", |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 2275 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
Marat Dukhan | f3f39f1 | 2017-12-11 13:32:05 +0900 | [diff] [blame] | 2276 | .model = 950, |
| 2277 | }, |
| 2278 | { |
| 2279 | /* "hi3660" -> HiSilicon Kirin 960 */ |
| 2280 | .platform = "hi3660", |
| 2281 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2282 | .model = 960, |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 2283 | }, |
| 2284 | { |
| 2285 | /* "mp523x" -> Renesas MP5232 */ |
| 2286 | .platform = "mp523x", |
| 2287 | .series = cpuinfo_arm_chipset_series_renesas_mp, |
| 2288 | .model = 5232, |
| 2289 | }, |
| 2290 | { |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 2291 | /* "BEETHOVEN" (Huawei MadiaPad M3) -> HiSilicon Kirin 950 */ |
| 2292 | .platform = "BEETHOVEN", |
| 2293 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2294 | .model = 950, |
| 2295 | }, |
| 2296 | { |
| 2297 | /* "hws7701u" (Huawei MediaPad 7 Youth) -> Rockchip RK3168 */ |
| 2298 | .platform = "hws7701u", |
| 2299 | .series = cpuinfo_arm_chipset_series_rockchip_rk, |
| 2300 | .model = 3168, |
| 2301 | }, |
| 2302 | { |
Marat Dukhan | 93982f2 | 2017-10-20 13:10:23 -0700 | [diff] [blame] | 2303 | /* "g2mv" (LG G2 mini LTE) -> Nvidia Tegra SL460N */ |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 2304 | .platform = "g2mv", |
| 2305 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_sl, |
| 2306 | .model = 460, |
| 2307 | .suffix = 'N', |
| 2308 | }, |
| 2309 | { |
| 2310 | /* "K00F" (Asus MeMO Pad 10) -> Rockchip RK3188 */ |
| 2311 | .platform = "K00F", |
| 2312 | .series = cpuinfo_arm_chipset_series_rockchip_rk, |
| 2313 | .model = 3188, |
| 2314 | }, |
| 2315 | { |
| 2316 | /* "T7H" (HP Slate 7) -> Rockchip RK3066 */ |
| 2317 | .platform = "T7H", |
| 2318 | .series = cpuinfo_arm_chipset_series_rockchip_rk, |
| 2319 | .model = 3066, |
| 2320 | }, |
| 2321 | { |
| 2322 | /* "tuna" (Samsung Galaxy Nexus) -> Texas Instruments OMAP4460 */ |
| 2323 | .platform = "tuna", |
| 2324 | .series = cpuinfo_arm_chipset_series_texas_instruments_omap, |
| 2325 | .model = 4460, |
| 2326 | }, |
| 2327 | { |
Marat Dukhan | 93982f2 | 2017-10-20 13:10:23 -0700 | [diff] [blame] | 2328 | /* "grouper" (Asus Nexus 7 2012) -> Nvidia Tegra T30L */ |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 2329 | .platform = "grouper", |
| 2330 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 2331 | .model = 30, |
| 2332 | .suffix = 'L', |
| 2333 | }, |
| 2334 | { |
Marat Dukhan | 93982f2 | 2017-10-20 13:10:23 -0700 | [diff] [blame] | 2335 | /* "flounder" (HTC Nexus 9) -> Nvidia Tegra T132 */ |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 2336 | .platform = "flounder", |
| 2337 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 2338 | .model = 132, |
| 2339 | }, |
| 2340 | { |
Marat Dukhan | 93982f2 | 2017-10-20 13:10:23 -0700 | [diff] [blame] | 2341 | /* "dragon" (Google Pixel C) -> Nvidia Tegra T210 */ |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 2342 | .platform = "dragon", |
| 2343 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 2344 | .model = 210, |
| 2345 | }, |
| 2346 | { |
| 2347 | /* "sailfish" (Google Pixel) -> Qualcomm MSM8996PRO */ |
| 2348 | .platform = "sailfish", |
| 2349 | .series = cpuinfo_arm_chipset_series_qualcomm_msm, |
| 2350 | .model = 8996, |
| 2351 | .suffix = 'P', |
| 2352 | }, |
| 2353 | { |
| 2354 | /* "marlin" (Google Pixel XL) -> Qualcomm MSM8996PRO */ |
| 2355 | .platform = "marlin", |
| 2356 | .series = cpuinfo_arm_chipset_series_qualcomm_msm, |
| 2357 | .model = 8996, |
| 2358 | .suffix = 'P', |
| 2359 | }, |
| 2360 | }; |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 2361 | |
| 2362 | /* |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 2363 | * Decodes chipset name from ro.product.board Android system property. |
| 2364 | * For some chipsets, the function relies frequency and on number of cores for chipset detection. |
| 2365 | * |
| 2366 | * @param[in] platform - ro.product.board value. |
| 2367 | * @param cores - number of cores in the chipset. |
| 2368 | * @param max_cpu_freq_max - maximum of /sys/devices/system/cpu/cpu<number>/cpofreq/cpu_freq_max values. |
| 2369 | * |
| 2370 | * @returns Decoded chipset name. If chipset could not be decoded, the resulting structure would use `unknown` vendor |
| 2371 | * and series identifiers. |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 2372 | */ |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 2373 | struct cpuinfo_arm_chipset cpuinfo_arm_android_decode_chipset_from_ro_product_board( |
| 2374 | const char ro_product_board[restrict static CPUINFO_BUILD_PROP_VALUE_MAX], |
| 2375 | uint32_t cores, uint32_t max_cpu_freq_max) |
| 2376 | { |
| 2377 | struct cpuinfo_arm_chipset chipset; |
| 2378 | const char* board = ro_product_board; |
| 2379 | const size_t board_length = strnlen(ro_product_board, CPUINFO_BUILD_PROP_VALUE_MAX); |
| 2380 | const char* board_end = ro_product_board + board_length; |
| 2381 | |
| 2382 | /* Check Qualcomm MSM/APQ signature */ |
| 2383 | if (match_msm_apq(board, board_end, &chipset)) { |
| 2384 | cpuinfo_log_debug( |
| 2385 | "matched Qualcomm MSM/APQ signature in ro.product.board string \"%.*s\"", (int) board_length, board); |
| 2386 | return chipset; |
| 2387 | } |
| 2388 | |
| 2389 | /* Check universaXXXX (Samsung Exynos) signature */ |
| 2390 | if (match_universal(board, board_end, &chipset)) { |
| 2391 | cpuinfo_log_debug( |
| 2392 | "matched UNIVERSAL (Samsung Exynos) signature in ro.product.board string \"%.*s\"", |
| 2393 | (int) board_length, board); |
| 2394 | return chipset; |
| 2395 | } |
| 2396 | |
| 2397 | /* Check SMDK (Samsung Exynos) signature */ |
| 2398 | if (match_and_parse_smdk(board, board_end, cores, &chipset)) { |
| 2399 | cpuinfo_log_debug( |
| 2400 | "matched SMDK (Samsung Exynos) signature in ro.product.board string \"%.*s\"", |
| 2401 | (int) board_length, board); |
| 2402 | return chipset; |
| 2403 | } |
| 2404 | |
| 2405 | /* Check MediaTek MT signature */ |
| 2406 | if (match_mt(board, board_end, true, &chipset)) { |
| 2407 | cpuinfo_log_debug( |
| 2408 | "matched MediaTek MT signature in ro.product.board string \"%.*s\"", |
| 2409 | (int) board_length, board); |
| 2410 | return chipset; |
| 2411 | } |
| 2412 | |
| 2413 | /* Check Spreadtrum SC signature */ |
| 2414 | if (match_sc(board, board_end, &chipset)) { |
| 2415 | cpuinfo_log_debug( |
| 2416 | "matched Spreadtrum SC signature in ro.product.board string \"%.*s\"", |
| 2417 | (int) board_length, board); |
| 2418 | return chipset; |
| 2419 | } |
| 2420 | |
| 2421 | /* Check Marvell PXA signature */ |
| 2422 | if (match_pxa(board, board_end, &chipset)) { |
| 2423 | cpuinfo_log_debug( |
| 2424 | "matched Marvell PXA signature in ro.product.board string \"%.*s\"", |
| 2425 | (int) board_length, board); |
| 2426 | return chipset; |
| 2427 | } |
| 2428 | |
| 2429 | /* Check Leadcore LCxxxx signature */ |
| 2430 | if (match_lc(board, board_end, &chipset)) { |
| 2431 | cpuinfo_log_debug( |
| 2432 | "matched Leadcore LC signature in ro.product.board string \"%.*s\"", |
| 2433 | (int) board_length, board); |
| 2434 | return chipset; |
| 2435 | } |
| 2436 | |
| 2437 | /* |
| 2438 | * Compare to tabulated ro.product.board values for Broadcom chipsets and decode chipset from frequency and |
| 2439 | * number of cores. |
| 2440 | */ |
| 2441 | if (match_and_parse_broadcom(board, board_end, cores, max_cpu_freq_max, &chipset)) { |
| 2442 | cpuinfo_log_debug( |
| 2443 | "found ro.product.board string \"%.*s\" in Broadcom chipset table", |
| 2444 | (int) board_length, board); |
| 2445 | return chipset; |
| 2446 | } |
| 2447 | |
| 2448 | /* Compare to tabulated ro.product.board values for Huawei devices which don't report chipset elsewhere */ |
| 2449 | if (match_and_parse_huawei(board, board_end, &chipset)) { |
| 2450 | cpuinfo_log_debug( |
| 2451 | "found ro.product.board string \"%.*s\" in Huawei chipset table", |
| 2452 | (int) board_length, board); |
| 2453 | return chipset; |
| 2454 | } |
| 2455 | |
| 2456 | /* Compare to tabulated ro.product.board values for popular chipsets/devices which can't be otherwise detected */ |
| 2457 | for (size_t i = 0; i < CPUINFO_COUNT_OF(special_board_map_entries); i++) { |
| 2458 | if (strncmp(special_board_map_entries[i].platform, board, board_length) == 0 && |
| 2459 | special_board_map_entries[i].platform[board_length] == 0) |
| 2460 | { |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 2461 | cpuinfo_log_debug( |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 2462 | "found ro.product.board string \"%.*s\" in special chipset table", |
| 2463 | (int) board_length, board); |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 2464 | /* Create chipset name from entry */ |
| 2465 | return (struct cpuinfo_arm_chipset) { |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 2466 | .vendor = chipset_series_vendor[special_board_map_entries[i].series], |
| 2467 | .series = (enum cpuinfo_arm_chipset_series) special_board_map_entries[i].series, |
| 2468 | .model = special_board_map_entries[i].model, |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 2469 | .suffix = { |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 2470 | [0] = special_board_map_entries[i].suffix, |
| 2471 | /* The suffix of MSM8996PRO is truncated at the first letter, reconstruct it here. */ |
| 2472 | [1] = special_board_map_entries[i].suffix == 'P' ? 'R' : 0, |
| 2473 | [2] = special_board_map_entries[i].suffix == 'P' ? 'O' : 0, |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 2474 | }, |
| 2475 | }; |
| 2476 | } |
| 2477 | } |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 2478 | |
| 2479 | return (struct cpuinfo_arm_chipset) { |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 2480 | .vendor = cpuinfo_arm_chipset_vendor_unknown, |
| 2481 | .series = cpuinfo_arm_chipset_series_unknown, |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 2482 | }; |
| 2483 | } |
| 2484 | |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 2485 | struct amlogic_map_entry { |
| 2486 | char ro_board_platform[6]; |
| 2487 | uint16_t model; |
| 2488 | uint8_t series; |
| 2489 | char suffix[3]; |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 2490 | }; |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 2491 | |
| 2492 | static const struct amlogic_map_entry amlogic_map_entries[] = { |
| 2493 | { |
| 2494 | /* "meson3" -> Amlogic AML8726-M */ |
| 2495 | .ro_board_platform = "meson3", |
| 2496 | .series = cpuinfo_arm_chipset_series_amlogic_aml, |
| 2497 | .model = 8726, |
| 2498 | .suffix = "-M", |
| 2499 | }, |
| 2500 | { |
| 2501 | /* "meson6" -> Amlogic AML8726-MX */ |
| 2502 | .ro_board_platform = "meson6", |
| 2503 | .series = cpuinfo_arm_chipset_series_amlogic_aml, |
| 2504 | .model = 8726, |
| 2505 | .suffix = "-MX", |
| 2506 | }, |
| 2507 | { |
| 2508 | /* "meson8" -> Amlogic S805 */ |
| 2509 | .ro_board_platform = "meson8", |
| 2510 | .series = cpuinfo_arm_chipset_series_amlogic_s, |
| 2511 | .model = 805, |
| 2512 | }, |
| 2513 | { |
| 2514 | /* "gxbaby" -> Amlogic S905 */ |
| 2515 | .ro_board_platform = "gxbaby", |
| 2516 | .series = cpuinfo_arm_chipset_series_amlogic_s, |
| 2517 | .model = 905, |
| 2518 | }, |
| 2519 | { |
| 2520 | /* "gxl" -> Amlogic S905X */ |
| 2521 | .ro_board_platform = "gxl", |
| 2522 | .series = cpuinfo_arm_chipset_series_amlogic_s, |
| 2523 | .model = 905, |
| 2524 | .suffix = "X", |
| 2525 | }, |
| 2526 | { |
| 2527 | /* "gxm" -> Amlogic S912 */ |
| 2528 | .ro_board_platform = "gxm", |
| 2529 | .series = cpuinfo_arm_chipset_series_amlogic_s, |
| 2530 | .model = 912, |
| 2531 | }, |
| 2532 | }; |
| 2533 | |
| 2534 | static const struct special_map_entry special_platform_map_entries[] = { |
| 2535 | { |
| 2536 | /* "hi6620oem" -> HiSilicon Kirin 910T */ |
| 2537 | .platform = "hi6620oem", |
| 2538 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2539 | .model = 910, |
| 2540 | .suffix = 'T', |
| 2541 | }, |
| 2542 | { |
| 2543 | /* "hi6250" -> HiSilicon Kirin 650 */ |
| 2544 | .platform = "hi6250", |
| 2545 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2546 | .model = 650, |
| 2547 | }, |
| 2548 | { |
| 2549 | /* "hi6210sft" -> HiSilicon Kirin 620 */ |
| 2550 | .platform = "hi6210sft", |
| 2551 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2552 | .model = 620, |
| 2553 | }, |
| 2554 | { |
Marat Dukhan | f3f39f1 | 2017-12-11 13:32:05 +0900 | [diff] [blame] | 2555 | /* "hi3630" -> HiSilicon Kirin 920 */ |
| 2556 | .platform = "hi3630", |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 2557 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
Marat Dukhan | f3f39f1 | 2017-12-11 13:32:05 +0900 | [diff] [blame] | 2558 | .model = 920, |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 2559 | }, |
| 2560 | { |
| 2561 | /* "hi3635" -> HiSilicon Kirin 930 */ |
| 2562 | .platform = "hi3635", |
| 2563 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2564 | .model = 930, |
| 2565 | }, |
| 2566 | { |
Marat Dukhan | f3f39f1 | 2017-12-11 13:32:05 +0900 | [diff] [blame] | 2567 | /* "hi3650" -> HiSilicon Kirin 950 */ |
| 2568 | .platform = "hi3650", |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 2569 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
Marat Dukhan | f3f39f1 | 2017-12-11 13:32:05 +0900 | [diff] [blame] | 2570 | .model = 950, |
| 2571 | }, |
| 2572 | { |
| 2573 | /* "hi3660" -> HiSilicon Kirin 960 */ |
| 2574 | .platform = "hi3660", |
| 2575 | .series = cpuinfo_arm_chipset_series_hisilicon_kirin, |
| 2576 | .model = 960, |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 2577 | }, |
| 2578 | { |
| 2579 | /* "k3v2oem1" -> HiSilicon K3V2 */ |
| 2580 | .platform = "k3v2oem1", |
| 2581 | .series = cpuinfo_arm_chipset_series_hisilicon_k3v, |
| 2582 | .model = 2, |
| 2583 | }, |
| 2584 | { |
| 2585 | /* "k3v200" -> HiSilicon K3V2 */ |
| 2586 | .platform = "k3v200", |
| 2587 | .series = cpuinfo_arm_chipset_series_hisilicon_k3v, |
| 2588 | .model = 2, |
| 2589 | }, |
| 2590 | { |
| 2591 | /* "montblanc" -> NovaThor U8500 */ |
| 2592 | .platform = "montblanc", |
| 2593 | .series = cpuinfo_arm_chipset_series_novathor_u, |
| 2594 | .model = 8500, |
| 2595 | }, |
| 2596 | { |
| 2597 | /* "song" -> Pinecone Surge S1 */ |
| 2598 | .platform = "song", |
| 2599 | .series = cpuinfo_arm_chipset_series_pinecone_surge_s, |
| 2600 | .model = 1, |
| 2601 | }, |
| 2602 | { |
Marat Dukhan | 40b4638 | 2018-03-07 08:30:59 -0800 | [diff] [blame] | 2603 | /* "rk322x" -> RockChip RK3229 */ |
| 2604 | .platform = "rk322x", |
| 2605 | .series = cpuinfo_arm_chipset_series_rockchip_rk, |
| 2606 | .model = 3229, |
| 2607 | }, |
| 2608 | { |
Marat Dukhan | 93982f2 | 2017-10-20 13:10:23 -0700 | [diff] [blame] | 2609 | /* "tegra132" -> Nvidia Tegra T132 */ |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 2610 | .platform = "tegra132", |
| 2611 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 2612 | .model = 132, |
| 2613 | }, |
| 2614 | { |
Marat Dukhan | 93982f2 | 2017-10-20 13:10:23 -0700 | [diff] [blame] | 2615 | /* "tegra210_dragon" -> Nvidia Tegra T210 */ |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 2616 | .platform = "tegra210_dragon", |
| 2617 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 2618 | .model = 210, |
| 2619 | }, |
| 2620 | { |
Marat Dukhan | 93982f2 | 2017-10-20 13:10:23 -0700 | [diff] [blame] | 2621 | /* "tegra4" -> Nvidia Tegra T114 */ |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 2622 | .platform = "tegra4", |
| 2623 | .series = cpuinfo_arm_chipset_series_nvidia_tegra_t, |
| 2624 | .model = 114, |
| 2625 | }, |
| 2626 | { |
| 2627 | /* "s5pc110" -> Samsung Exynos 3110 */ |
| 2628 | .platform = "s5pc110", |
| 2629 | .series = cpuinfo_arm_chipset_series_samsung_exynos, |
| 2630 | .model = 3110, |
| 2631 | }, |
| 2632 | }; |
| 2633 | |
| 2634 | /* |
| 2635 | * Decodes chipset name from ro.board.platform Android system property. |
| 2636 | * For some chipsets, the function relies frequency and on number of cores for chipset detection. |
| 2637 | * |
| 2638 | * @param[in] platform - ro.board.platform value. |
| 2639 | * @param cores - number of cores in the chipset. |
| 2640 | * @param max_cpu_freq_max - maximum of /sys/devices/system/cpu/cpu<number>/cpofreq/cpu_freq_max values. |
| 2641 | * |
| 2642 | * @returns Decoded chipset name. If chipset could not be decoded, the resulting structure would use `unknown` vendor |
| 2643 | * and series identifiers. |
| 2644 | */ |
| 2645 | struct cpuinfo_arm_chipset cpuinfo_arm_android_decode_chipset_from_ro_board_platform( |
| 2646 | const char platform[restrict static CPUINFO_BUILD_PROP_VALUE_MAX], |
| 2647 | uint32_t cores, uint32_t max_cpu_freq_max) |
| 2648 | { |
| 2649 | struct cpuinfo_arm_chipset chipset; |
| 2650 | const size_t platform_length = strnlen(platform, CPUINFO_BUILD_PROP_VALUE_MAX); |
| 2651 | const char* platform_end = platform + platform_length; |
| 2652 | |
| 2653 | /* Check Qualcomm MSM/APQ signature */ |
| 2654 | if (match_msm_apq(platform, platform_end, &chipset)) { |
| 2655 | cpuinfo_log_debug( |
| 2656 | "matched Qualcomm MSM/APQ signature in ro.board.platform string \"%.*s\"", |
| 2657 | (int) platform_length, platform); |
| 2658 | return chipset; |
| 2659 | } |
| 2660 | |
| 2661 | /* Check exynosXXXX (Samsung Exynos) signature */ |
| 2662 | if (match_exynos(platform, platform_end, &chipset)) { |
| 2663 | cpuinfo_log_debug( |
| 2664 | "matched exynosXXXX (Samsung Exynos) signature in ro.board.platform string \"%.*s\"", |
| 2665 | (int) platform_length, platform); |
| 2666 | return chipset; |
| 2667 | } |
| 2668 | |
| 2669 | /* Check MediaTek MT signature */ |
| 2670 | if (match_mt(platform, platform_end, true, &chipset)) { |
| 2671 | cpuinfo_log_debug( |
| 2672 | "matched MediaTek MT signature in ro.board.platform string \"%.*s\"", (int) platform_length, platform); |
| 2673 | return chipset; |
| 2674 | } |
| 2675 | |
Marat Dukhan | 166ce4c | 2017-11-27 14:54:43 -0800 | [diff] [blame] | 2676 | /* Check HiSilicon Kirin signature */ |
| 2677 | if (match_kirin(platform, platform_end, &chipset)) { |
| 2678 | cpuinfo_log_debug( |
| 2679 | "matched HiSilicon Kirin signature in ro.board.platform string \"%.*s\"", (int) platform_length, platform); |
| 2680 | return chipset; |
| 2681 | } |
| 2682 | |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 2683 | /* Check Spreadtrum SC signature */ |
| 2684 | if (match_sc(platform, platform_end, &chipset)) { |
| 2685 | cpuinfo_log_debug( |
| 2686 | "matched Spreadtrum SC signature in ro.board.platform string \"%.*s\"", (int) platform_length, platform); |
| 2687 | return chipset; |
| 2688 | } |
| 2689 | |
| 2690 | /* Check Rockchip RK signature */ |
| 2691 | if (match_rk(platform, platform_end, &chipset)) { |
| 2692 | cpuinfo_log_debug( |
| 2693 | "matched Rockchip RK signature in ro.board.platform string \"%.*s\"", (int) platform_length, platform); |
| 2694 | return chipset; |
| 2695 | } |
| 2696 | |
| 2697 | /* Check Leadcore LCxxxx signature */ |
| 2698 | if (match_lc(platform, platform_end, &chipset)) { |
| 2699 | cpuinfo_log_debug( |
| 2700 | "matched Leadcore LC signature in ro.board.platform string \"%.*s\"", (int) platform_length, platform); |
| 2701 | return chipset; |
| 2702 | } |
| 2703 | |
| 2704 | /* Compare to tabulated ro.board.platform values for Huawei devices which don't report chipset elsewhere */ |
| 2705 | if (match_and_parse_huawei(platform, platform_end, &chipset)) { |
| 2706 | cpuinfo_log_debug( |
| 2707 | "found ro.board.platform string \"%.*s\" in Huawei chipset table", |
| 2708 | (int) platform_length, platform); |
| 2709 | return chipset; |
| 2710 | } |
| 2711 | |
| 2712 | /* |
| 2713 | * Compare to known ro.board.platform values for Broadcom devices and |
| 2714 | * detect chipset from frequency and number of cores |
| 2715 | */ |
| 2716 | if (match_and_parse_broadcom(platform, platform_end, cores, max_cpu_freq_max, &chipset)) { |
| 2717 | cpuinfo_log_debug( |
| 2718 | "found ro.board.platform string \"%.*s\" in Broadcom chipset table", |
| 2719 | (int) platform_length, platform); |
| 2720 | return chipset; |
| 2721 | } |
| 2722 | |
| 2723 | /* |
| 2724 | * Compare to ro.board.platform value ("omap4") for OMAP4xxx chipsets. |
| 2725 | * Upon successful match, detect OMAP4430 from frequency and number of cores. |
| 2726 | */ |
| 2727 | if (platform_length == 5 && cores == 2 && max_cpu_freq_max == 1008000 && memcmp(platform, "omap4", 5) == 0) { |
| 2728 | cpuinfo_log_debug( |
| 2729 | "matched Texas Instruments OMAP4 signature in ro.board.platform string \"%.*s\"", |
| 2730 | (int) platform_length, platform); |
| 2731 | |
| 2732 | return (struct cpuinfo_arm_chipset) { |
| 2733 | .vendor = cpuinfo_arm_chipset_vendor_texas_instruments, |
| 2734 | .series = cpuinfo_arm_chipset_series_texas_instruments_omap, |
| 2735 | .model = 4430, |
| 2736 | }; |
| 2737 | } |
| 2738 | |
| 2739 | /* |
| 2740 | * Compare to tabulated ro.board.platform values for Amlogic chipsets/devices which can't be otherwise detected. |
| 2741 | * The tabulated Amlogic ro.board.platform values have not more than 6 characters. |
| 2742 | */ |
| 2743 | if (platform_length <= 6) { |
| 2744 | for (size_t i = 0; i < CPUINFO_COUNT_OF(amlogic_map_entries); i++) { |
| 2745 | if (strncmp(amlogic_map_entries[i].ro_board_platform, platform, 6) == 0) { |
| 2746 | cpuinfo_log_debug( |
| 2747 | "found ro.board.platform string \"%.*s\" in Amlogic chipset table", |
| 2748 | (int) platform_length, platform); |
| 2749 | /* Create chipset name from entry */ |
| 2750 | return (struct cpuinfo_arm_chipset) { |
| 2751 | .vendor = cpuinfo_arm_chipset_vendor_amlogic, |
| 2752 | .series = (enum cpuinfo_arm_chipset_series) amlogic_map_entries[i].series, |
| 2753 | .model = amlogic_map_entries[i].model, |
| 2754 | .suffix = { |
| 2755 | [0] = amlogic_map_entries[i].suffix[0], |
| 2756 | [1] = amlogic_map_entries[i].suffix[1], |
| 2757 | [2] = amlogic_map_entries[i].suffix[2], |
| 2758 | }, |
| 2759 | }; |
| 2760 | } |
| 2761 | } |
| 2762 | } |
| 2763 | |
| 2764 | /* Compare to tabulated ro.board.platform values for popular chipsets/devices which can't be otherwise detected */ |
| 2765 | for (size_t i = 0; i < CPUINFO_COUNT_OF(special_platform_map_entries); i++) { |
| 2766 | if (strncmp(special_platform_map_entries[i].platform, platform, platform_length) == 0 && |
| 2767 | special_platform_map_entries[i].platform[platform_length] == 0) |
| 2768 | { |
| 2769 | /* Create chipset name from entry */ |
| 2770 | cpuinfo_log_debug( |
| 2771 | "found ro.board.platform string \"%.*s\" in special chipset table", (int) platform_length, platform); |
| 2772 | return (struct cpuinfo_arm_chipset) { |
| 2773 | .vendor = chipset_series_vendor[special_platform_map_entries[i].series], |
| 2774 | .series = (enum cpuinfo_arm_chipset_series) special_platform_map_entries[i].series, |
| 2775 | .model = special_platform_map_entries[i].model, |
| 2776 | .suffix = { |
| 2777 | [0] = special_platform_map_entries[i].suffix, |
| 2778 | }, |
| 2779 | }; |
| 2780 | } |
| 2781 | } |
| 2782 | |
| 2783 | /* None of the ro.board.platform signatures matched, indicate unknown chipset */ |
| 2784 | return (struct cpuinfo_arm_chipset) { |
| 2785 | .vendor = cpuinfo_arm_chipset_vendor_unknown, |
| 2786 | .series = cpuinfo_arm_chipset_series_unknown, |
| 2787 | }; |
| 2788 | } |
| 2789 | |
| 2790 | /* |
| 2791 | * Decodes chipset name from ro.mediatek.platform Android system property. |
| 2792 | * |
| 2793 | * @param[in] platform - ro.mediatek.platform value. |
| 2794 | * |
Marat Dukhan | e5d6049 | 2018-03-08 12:47:27 -0800 | [diff] [blame] | 2795 | * @returns Decoded chipset name. If chipset could not be decoded, the resulting structure would use `unknown` |
| 2796 | * vendor and series identifiers. |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 2797 | */ |
| 2798 | struct cpuinfo_arm_chipset cpuinfo_arm_android_decode_chipset_from_ro_mediatek_platform( |
| 2799 | const char platform[restrict static CPUINFO_BUILD_PROP_VALUE_MAX]) |
| 2800 | { |
| 2801 | struct cpuinfo_arm_chipset chipset; |
Marat Dukhan | e5d6049 | 2018-03-08 12:47:27 -0800 | [diff] [blame] | 2802 | const char* platform_end = platform + strnlen(platform, CPUINFO_BUILD_PROP_VALUE_MAX); |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 2803 | |
| 2804 | /* Check MediaTek MT signature */ |
| 2805 | if (match_mt(platform, platform_end, false, &chipset)) { |
| 2806 | return chipset; |
| 2807 | } |
| 2808 | |
| 2809 | return (struct cpuinfo_arm_chipset) { |
| 2810 | .vendor = cpuinfo_arm_chipset_vendor_unknown, |
| 2811 | .series = cpuinfo_arm_chipset_series_unknown, |
| 2812 | }; |
| 2813 | } |
| 2814 | |
Marat Dukhan | e5d6049 | 2018-03-08 12:47:27 -0800 | [diff] [blame] | 2815 | |
| 2816 | /* |
| 2817 | * Decodes chipset name from ro.arch Android system property. |
| 2818 | * |
| 2819 | * The ro.arch property is matched only against Samsung Exynos signature. Systems with other chipset rarely |
| 2820 | * configure ro.arch Android system property, and can be decoded through other properties, but some Exynos |
| 2821 | * chipsets are identified only in ro.arch. |
| 2822 | * |
| 2823 | * @param[in] arch - ro.arch value. |
| 2824 | * |
| 2825 | * @returns Decoded chipset name. If chipset could not be decoded, the resulting structure would use `unknown` |
| 2826 | * vendor and series identifiers. |
| 2827 | */ |
| 2828 | struct cpuinfo_arm_chipset cpuinfo_arm_android_decode_chipset_from_ro_arch( |
| 2829 | const char arch[restrict static CPUINFO_BUILD_PROP_VALUE_MAX]) |
| 2830 | { |
| 2831 | struct cpuinfo_arm_chipset chipset; |
| 2832 | const char* arch_end = arch + strnlen(arch, CPUINFO_BUILD_PROP_VALUE_MAX); |
| 2833 | |
| 2834 | /* Check Samsung exynosXXXX signature */ |
| 2835 | if (match_exynos(arch, arch_end, &chipset)) { |
| 2836 | return chipset; |
| 2837 | } |
| 2838 | |
| 2839 | return (struct cpuinfo_arm_chipset) { |
| 2840 | .vendor = cpuinfo_arm_chipset_vendor_unknown, |
| 2841 | .series = cpuinfo_arm_chipset_series_unknown, |
| 2842 | }; |
| 2843 | } |
| 2844 | |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 2845 | /* |
| 2846 | * Decodes chipset name from ro.chipname Android system property. |
| 2847 | * |
| 2848 | * @param[in] chipname - ro.chipname value. |
| 2849 | * |
| 2850 | * @returns Decoded chipset name. If chipset could not be decoded, the resulting structure would use `unknown` vendor |
| 2851 | * and series identifiers. |
| 2852 | */ |
| 2853 | struct cpuinfo_arm_chipset cpuinfo_arm_android_decode_chipset_from_ro_chipname( |
| 2854 | const char chipname[restrict static CPUINFO_BUILD_PROP_VALUE_MAX]) |
| 2855 | { |
| 2856 | struct cpuinfo_arm_chipset chipset; |
| 2857 | const size_t chipname_length = strnlen(chipname, CPUINFO_BUILD_PROP_VALUE_MAX); |
| 2858 | const char* chipname_end = chipname + chipname_length; |
| 2859 | |
| 2860 | /* Check Qualcomm MSM/APQ signatures */ |
| 2861 | if (match_msm_apq(chipname, chipname_end, &chipset)) { |
| 2862 | cpuinfo_log_debug( |
| 2863 | "matched Qualcomm MSM/APQ signature in ro.chipname string \"%.*s\"", |
| 2864 | (int) chipname_length, chipname); |
| 2865 | return chipset; |
| 2866 | } |
| 2867 | |
| 2868 | /* Check exynosXXXX (Samsung Exynos) signature */ |
| 2869 | if (match_exynos(chipname, chipname_end, &chipset)) { |
| 2870 | cpuinfo_log_debug( |
| 2871 | "matched exynosXXXX (Samsung Exynos) signature in ro.chipname string \"%.*s\"", |
| 2872 | (int) chipname_length, chipname); |
| 2873 | return chipset; |
| 2874 | } |
| 2875 | |
| 2876 | /* Check universalXXXX (Samsung Exynos) signature */ |
| 2877 | if (match_universal(chipname, chipname_end, &chipset)) { |
| 2878 | cpuinfo_log_debug( |
| 2879 | "matched UNIVERSAL (Samsung Exynos) signature in ro.chipname Hardware string \"%.*s\"", |
| 2880 | (int) chipname_length, chipname); |
| 2881 | return chipset; |
| 2882 | } |
| 2883 | |
| 2884 | /* Check MediaTek MT signature */ |
| 2885 | if (match_mt(chipname, chipname_end, true, &chipset)) { |
| 2886 | cpuinfo_log_debug( |
| 2887 | "matched MediaTek MT signature in ro.chipname string \"%.*s\"", |
| 2888 | (int) chipname_length, chipname); |
| 2889 | return chipset; |
| 2890 | } |
| 2891 | |
| 2892 | /* Check Spreadtrum SC signature */ |
| 2893 | if (match_sc(chipname, chipname_end, &chipset)) { |
| 2894 | cpuinfo_log_debug( |
| 2895 | "matched Spreadtrum SC signature in ro.chipname string \"%.*s\"", |
| 2896 | (int) chipname_length, chipname); |
| 2897 | return chipset; |
| 2898 | } |
| 2899 | |
| 2900 | /* Check Marvell PXA signature */ |
| 2901 | if (match_pxa(chipname, chipname_end, &chipset)) { |
| 2902 | cpuinfo_log_debug( |
| 2903 | "matched Marvell PXA signature in ro.chipname string \"%.*s\"", |
| 2904 | (int) chipname_length, chipname); |
| 2905 | return chipset; |
| 2906 | } |
| 2907 | |
| 2908 | /* Compare to ro.chipname value ("mp523x") for Renesas MP5232 which can't be otherwise detected */ |
| 2909 | if (chipname_length == 6 && memcmp(chipname, "mp523x", 6) == 0) { |
| 2910 | cpuinfo_log_debug( |
| 2911 | "matched Renesas MP5232 signature in ro.chipname string \"%.*s\"", |
| 2912 | (int) chipname_length, chipname); |
| 2913 | |
| 2914 | return (struct cpuinfo_arm_chipset) { |
| 2915 | .vendor = cpuinfo_arm_chipset_vendor_renesas, |
| 2916 | .series = cpuinfo_arm_chipset_series_renesas_mp, |
| 2917 | .model = 5232, |
| 2918 | }; |
| 2919 | } |
| 2920 | |
| 2921 | return (struct cpuinfo_arm_chipset) { |
| 2922 | .vendor = cpuinfo_arm_chipset_vendor_unknown, |
| 2923 | .series = cpuinfo_arm_chipset_series_unknown, |
| 2924 | }; |
| 2925 | } |
| 2926 | #endif /* __ANDROID__ */ |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 2927 | |
| 2928 | /* |
| 2929 | * Fix common bugs, typos, and renames in chipset name. |
| 2930 | * |
| 2931 | * @param[in,out] chipset - chipset name to fix. |
| 2932 | * @param cores - number of cores in the chipset. |
| 2933 | * @param max_cpu_freq_max - maximum of /sys/devices/system/cpu/cpu<number>/cpofreq/cpu_freq_max values. |
| 2934 | */ |
| 2935 | void cpuinfo_arm_fixup_chipset( |
| 2936 | struct cpuinfo_arm_chipset chipset[restrict static 1], uint32_t cores, uint32_t max_cpu_freq_max) |
| 2937 | { |
| 2938 | switch (chipset->series) { |
| 2939 | case cpuinfo_arm_chipset_series_qualcomm_msm: |
| 2940 | /* Check if there is suffix */ |
| 2941 | if (chipset->suffix[0] == 0) { |
| 2942 | /* No suffix, but the model may be misreported */ |
| 2943 | switch (chipset->model) { |
| 2944 | case 8216: |
| 2945 | /* MSM8216 was renamed to MSM8916 */ |
| 2946 | cpuinfo_log_info("reinterpreted MSM8216 chipset as MSM8916"); |
| 2947 | chipset->model = 8916; |
| 2948 | break; |
| 2949 | case 8916: |
| 2950 | /* Common bug: MSM8939 (Octa-core) reported as MSM8916 (Quad-core) */ |
| 2951 | switch (cores) { |
| 2952 | case 4: |
| 2953 | break; |
| 2954 | case 8: |
| 2955 | cpuinfo_log_info("reinterpreted MSM8916 chipset with 8 cores as MSM8939"); |
| 2956 | chipset->model = 8939; |
| 2957 | break; |
| 2958 | default: |
| 2959 | cpuinfo_log_warning("system reported invalid %"PRIu32"-core MSM%"PRIu32" chipset", |
| 2960 | cores, chipset->model); |
| 2961 | chipset->model = 0; |
| 2962 | } |
| 2963 | break; |
| 2964 | case 8937: |
| 2965 | /* Common bug: MSM8917 (Quad-core) reported as MSM8937 (Octa-core) */ |
| 2966 | switch (cores) { |
| 2967 | case 4: |
| 2968 | cpuinfo_log_info("reinterpreted MSM8937 chipset with 4 cores as MSM8917"); |
| 2969 | chipset->model = 8917; |
| 2970 | break; |
| 2971 | case 8: |
| 2972 | break; |
| 2973 | default: |
| 2974 | cpuinfo_log_warning("system reported invalid %"PRIu32"-core MSM%"PRIu32" chipset", |
| 2975 | cores, chipset->model); |
| 2976 | chipset->model = 0; |
| 2977 | } |
| 2978 | break; |
| 2979 | case 8960: |
| 2980 | /* Common bug: APQ8064 (Quad-core) reported as MSM8960 (Dual-core) */ |
| 2981 | switch (cores) { |
| 2982 | case 2: |
| 2983 | break; |
| 2984 | case 4: |
| 2985 | cpuinfo_log_info("reinterpreted MSM8960 chipset with 4 cores as APQ8064"); |
| 2986 | chipset->series = cpuinfo_arm_chipset_series_qualcomm_apq; |
| 2987 | chipset->model = 8064; |
| 2988 | break; |
| 2989 | default: |
| 2990 | cpuinfo_log_warning("system reported invalid %"PRIu32"-core MSM%"PRIu32" chipset", |
| 2991 | cores, chipset->model); |
| 2992 | chipset->model = 0; |
| 2993 | } |
| 2994 | break; |
| 2995 | case 8996: |
| 2996 | /* Common bug: MSM8994 (Octa-core) reported as MSM8996 (Quad-core) */ |
| 2997 | switch (cores) { |
| 2998 | case 4: |
| 2999 | break; |
| 3000 | case 8: |
| 3001 | cpuinfo_log_info("reinterpreted MSM8996 chipset with 8 cores as MSM8994"); |
| 3002 | chipset->model = 8994; |
| 3003 | break; |
| 3004 | default: |
| 3005 | cpuinfo_log_warning("system reported invalid %"PRIu32"-core MSM%"PRIu32" chipset", |
| 3006 | cores, chipset->model); |
| 3007 | chipset->model = 0; |
| 3008 | } |
| 3009 | break; |
| 3010 | case 8610: |
Marat Dukhan | f928231 | 2017-12-11 13:33:12 +0900 | [diff] [blame] | 3011 | /* Common bug: MSM8612 (Quad-core) reported as MSM8610 (Dual-core) */ |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 3012 | switch (cores) { |
| 3013 | case 2: |
| 3014 | break; |
| 3015 | case 4: |
Marat Dukhan | f928231 | 2017-12-11 13:33:12 +0900 | [diff] [blame] | 3016 | cpuinfo_log_info("reinterpreted MSM8610 chipset with 4 cores as MSM8612"); |
| 3017 | chipset->model = 8612; |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 3018 | break; |
| 3019 | default: |
| 3020 | cpuinfo_log_warning("system reported invalid %"PRIu32"-core MSM%"PRIu32" chipset", |
| 3021 | cores, chipset->model); |
| 3022 | chipset->model = 0; |
| 3023 | } |
| 3024 | break; |
| 3025 | } |
| 3026 | } else { |
| 3027 | /* Suffix may need correction */ |
| 3028 | const uint32_t suffix_word = load_u32le(chipset->suffix); |
| 3029 | if (suffix_word == UINT32_C(0x004D534D) /* "\0MSM" = reverse("MSM\0") */) { |
| 3030 | /* |
| 3031 | * Common bug: model name repeated twice, e.g. "MSM8916MSM8916" |
| 3032 | * In this case, model matching code parses the second "MSM" as a suffix |
| 3033 | */ |
| 3034 | chipset->suffix[0] = 0; |
| 3035 | chipset->suffix[1] = 0; |
| 3036 | chipset->suffix[2] = 0; |
| 3037 | } else { |
| 3038 | switch (chipset->model) { |
| 3039 | case 8976: |
| 3040 | /* MSM8976SG -> MSM8976PRO */ |
| 3041 | if (suffix_word == UINT32_C(0x00004753) /* "\0\0GS" = reverse("SG\0\0") */ ) { |
| 3042 | chipset->suffix[0] = 'P'; |
| 3043 | chipset->suffix[1] = 'R'; |
| 3044 | chipset->suffix[2] = 'O'; |
| 3045 | } |
| 3046 | break; |
| 3047 | case 8996: |
| 3048 | /* MSM8996PRO -> MSM8996PRO-AB or MSM8996PRO-AC */ |
| 3049 | if (suffix_word == UINT32_C(0x004F5250) /* "\0ORP" = reverse("PRO\0") */ ) { |
| 3050 | chipset->suffix[3] = '-'; |
| 3051 | chipset->suffix[4] = 'A'; |
| 3052 | chipset->suffix[5] = 'B' + (char) (max_cpu_freq_max >= 2188800); |
| 3053 | } |
| 3054 | break; |
| 3055 | } |
| 3056 | } |
| 3057 | } |
| 3058 | break; |
| 3059 | case cpuinfo_arm_chipset_series_qualcomm_apq: |
| 3060 | { |
| 3061 | /* Suffix may need correction */ |
| 3062 | const uint32_t expected_apq = load_u32le(chipset->suffix); |
| 3063 | if (expected_apq == UINT32_C(0x00515041) /* "\0QPA" = reverse("APQ\0") */) { |
| 3064 | /* |
| 3065 | * Common bug: model name repeated twice, e.g. "APQ8016APQ8016" |
| 3066 | * In this case, model matching code parses the second "APQ" as a suffix |
| 3067 | */ |
| 3068 | chipset->suffix[0] = 0; |
| 3069 | chipset->suffix[1] = 0; |
| 3070 | chipset->suffix[2] = 0; |
| 3071 | } |
| 3072 | break; |
| 3073 | } |
| 3074 | case cpuinfo_arm_chipset_series_samsung_exynos: |
Marat Dukhan | 2563229 | 2017-12-15 11:25:27 -0800 | [diff] [blame] | 3075 | switch (chipset->model) { |
| 3076 | case 4410: |
| 3077 | /* Exynos 4410 was renamed to Exynos 4412 */ |
| 3078 | chipset->model = 4412; |
| 3079 | break; |
Marat Dukhan | ab7f949 | 2018-03-08 13:06:40 -0800 | [diff] [blame^] | 3080 | case 5420: |
| 3081 | /* Common bug: Exynos 5260 (Hexa-core) reported as Exynos 5420 (Quad-core) */ |
| 3082 | switch (cores) { |
| 3083 | case 4: |
| 3084 | break; |
| 3085 | case 6: |
| 3086 | cpuinfo_log_info("reinterpreted Exynos 5420 chipset with 6 cores as Exynos 5260"); |
| 3087 | chipset->model = 5260; |
| 3088 | break; |
| 3089 | default: |
| 3090 | cpuinfo_log_warning("system reported invalid %"PRIu32"-core Exynos 5420 chipset", cores); |
| 3091 | chipset->model = 0; |
| 3092 | } |
| 3093 | break; |
Marat Dukhan | 2563229 | 2017-12-15 11:25:27 -0800 | [diff] [blame] | 3094 | case 7580: |
| 3095 | /* Common bug: Exynos 7578 (Quad-core) reported as Exynos 7580 (Octa-core) */ |
| 3096 | switch (cores) { |
| 3097 | case 4: |
| 3098 | cpuinfo_log_info("reinterpreted Exynos 7580 chipset with 4 cores as Exynos 7578"); |
| 3099 | chipset->model = 7578; |
| 3100 | break; |
| 3101 | case 8: |
| 3102 | break; |
| 3103 | default: |
| 3104 | cpuinfo_log_warning("system reported invalid %"PRIu32"-core Exynos 7580 chipset", cores); |
| 3105 | chipset->model = 0; |
| 3106 | } |
| 3107 | break; |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 3108 | } |
| 3109 | break; |
| 3110 | case cpuinfo_arm_chipset_series_mediatek_mt: |
| 3111 | if (chipset->model == 6752) { |
| 3112 | /* Common bug: MT6732 (Quad-core) reported as MT6752 (Octa-core) */ |
| 3113 | switch (cores) { |
| 3114 | case 4: |
| 3115 | cpuinfo_log_info("reinterpreted MT6752 chipset with 4 cores as MT6732"); |
| 3116 | chipset->model = 6732; |
| 3117 | break; |
| 3118 | case 8: |
| 3119 | break; |
| 3120 | default: |
| 3121 | cpuinfo_log_warning("system reported invalid %"PRIu32"-core MT6752 chipset", cores); |
| 3122 | chipset->model = 0; |
| 3123 | } |
| 3124 | } |
| 3125 | if (chipset->suffix[0] == 'T') { |
| 3126 | /* Normalization: "TURBO" and "TRUBO" (apparently a typo) -> "T" */ |
| 3127 | const uint32_t suffix_word = load_u32le(chipset->suffix + 1); |
| 3128 | switch (suffix_word) { |
| 3129 | case UINT32_C(0x4F425255): /* "OBRU" = reverse("URBO") */ |
| 3130 | case UINT32_C(0x4F425552): /* "OBUR" = reverse("RUBO") */ |
| 3131 | if (chipset->suffix[5] == 0) { |
| 3132 | chipset->suffix[1] = 0; |
| 3133 | chipset->suffix[2] = 0; |
| 3134 | chipset->suffix[3] = 0; |
| 3135 | chipset->suffix[4] = 0; |
| 3136 | } |
| 3137 | break; |
| 3138 | } |
| 3139 | } |
| 3140 | break; |
Marat Dukhan | a34a16b | 2018-03-08 10:14:50 -0800 | [diff] [blame] | 3141 | case cpuinfo_arm_chipset_series_rockchip_rk: |
Marat Dukhan | f166242 | 2018-03-08 12:52:29 -0800 | [diff] [blame] | 3142 | if (chipset->model == 3288) { |
Marat Dukhan | a34a16b | 2018-03-08 10:14:50 -0800 | [diff] [blame] | 3143 | /* Common bug: Rockchip RK3399 (Hexa-core) always reported as RK3288 (Quad-core) */ |
Marat Dukhan | f166242 | 2018-03-08 12:52:29 -0800 | [diff] [blame] | 3144 | switch (cores) { |
| 3145 | case 4: |
| 3146 | break; |
| 3147 | case 6: |
| 3148 | cpuinfo_log_info("reinterpreted RK3288 chipset with 6 cores as RK3399"); |
| 3149 | chipset->model = 3399; |
| 3150 | break; |
| 3151 | default: |
| 3152 | cpuinfo_log_warning("system reported invalid %"PRIu32"-core RK3288 chipset", cores); |
| 3153 | chipset->model = 0; |
| 3154 | } |
Marat Dukhan | a34a16b | 2018-03-08 10:14:50 -0800 | [diff] [blame] | 3155 | } |
| 3156 | break; |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 3157 | default: |
| 3158 | break; |
| 3159 | } |
| 3160 | } |
| 3161 | |
| 3162 | /* Map from ARM chipset vendor ID to its string representation */ |
| 3163 | static const char* chipset_vendor_string[cpuinfo_arm_chipset_vendor_max] = { |
| 3164 | [cpuinfo_arm_chipset_vendor_unknown] = "Unknown", |
| 3165 | [cpuinfo_arm_chipset_vendor_qualcomm] = "Qualcomm", |
| 3166 | [cpuinfo_arm_chipset_vendor_mediatek] = "MediaTek", |
| 3167 | [cpuinfo_arm_chipset_vendor_samsung] = "Samsung", |
| 3168 | [cpuinfo_arm_chipset_vendor_hisilicon] = "HiSilicon", |
| 3169 | [cpuinfo_arm_chipset_vendor_actions] = "Actions", |
| 3170 | [cpuinfo_arm_chipset_vendor_allwinner] = "Allwinner", |
| 3171 | [cpuinfo_arm_chipset_vendor_amlogic] = "Amlogic", |
| 3172 | [cpuinfo_arm_chipset_vendor_broadcom] = "Broadcom", |
| 3173 | [cpuinfo_arm_chipset_vendor_lg] = "LG", |
| 3174 | [cpuinfo_arm_chipset_vendor_leadcore] = "Leadcore", |
| 3175 | [cpuinfo_arm_chipset_vendor_marvell] = "Marvell", |
| 3176 | [cpuinfo_arm_chipset_vendor_mstar] = "MStar", |
| 3177 | [cpuinfo_arm_chipset_vendor_novathor] = "NovaThor", |
Marat Dukhan | 93982f2 | 2017-10-20 13:10:23 -0700 | [diff] [blame] | 3178 | [cpuinfo_arm_chipset_vendor_nvidia] = "Nvidia", |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 3179 | [cpuinfo_arm_chipset_vendor_pinecone] = "Pinecone", |
| 3180 | [cpuinfo_arm_chipset_vendor_renesas] = "Renesas", |
| 3181 | [cpuinfo_arm_chipset_vendor_rockchip] = "Rockchip", |
| 3182 | [cpuinfo_arm_chipset_vendor_spreadtrum] = "Spreadtrum", |
| 3183 | [cpuinfo_arm_chipset_vendor_telechips] = "Telechips", |
| 3184 | [cpuinfo_arm_chipset_vendor_texas_instruments] = "Texas Instruments", |
| 3185 | [cpuinfo_arm_chipset_vendor_wondermedia] = "WonderMedia", |
| 3186 | }; |
| 3187 | |
| 3188 | /* Map from ARM chipset series ID to its string representation */ |
| 3189 | static const char* chipset_series_string[cpuinfo_arm_chipset_series_max] = { |
| 3190 | [cpuinfo_arm_chipset_series_unknown] = NULL, |
| 3191 | [cpuinfo_arm_chipset_series_qualcomm_qsd] = "QSD", |
| 3192 | [cpuinfo_arm_chipset_series_qualcomm_msm] = "MSM", |
| 3193 | [cpuinfo_arm_chipset_series_qualcomm_apq] = "APQ", |
| 3194 | [cpuinfo_arm_chipset_series_qualcomm_snapdragon] = "Snapdragon ", |
| 3195 | [cpuinfo_arm_chipset_series_mediatek_mt] = "MT", |
| 3196 | [cpuinfo_arm_chipset_series_samsung_exynos] = "Exynos ", |
| 3197 | [cpuinfo_arm_chipset_series_hisilicon_k3v] = "K3V", |
| 3198 | [cpuinfo_arm_chipset_series_hisilicon_hi] = "Hi", |
| 3199 | [cpuinfo_arm_chipset_series_hisilicon_kirin] = "Kirin ", |
| 3200 | [cpuinfo_arm_chipset_series_actions_atm] = "ATM", |
| 3201 | [cpuinfo_arm_chipset_series_allwinner_a] = "A", |
| 3202 | [cpuinfo_arm_chipset_series_amlogic_aml] = "AML", |
| 3203 | [cpuinfo_arm_chipset_series_amlogic_s] = "S", |
| 3204 | [cpuinfo_arm_chipset_series_broadcom_bcm] = "BCM", |
| 3205 | [cpuinfo_arm_chipset_series_lg_nuclun] = "Nuclun ", |
| 3206 | [cpuinfo_arm_chipset_series_leadcore_lc] = "LC", |
| 3207 | [cpuinfo_arm_chipset_series_marvell_pxa] = "PXA", |
| 3208 | [cpuinfo_arm_chipset_series_mstar_6a] = "6A", |
| 3209 | [cpuinfo_arm_chipset_series_novathor_u] = "U", |
| 3210 | [cpuinfo_arm_chipset_series_nvidia_tegra_t] = "Tegra T", |
| 3211 | [cpuinfo_arm_chipset_series_nvidia_tegra_ap] = "Tegra AP", |
| 3212 | [cpuinfo_arm_chipset_series_nvidia_tegra_sl] = "Tegra SL", |
| 3213 | [cpuinfo_arm_chipset_series_pinecone_surge_s] = "Surge S", |
| 3214 | [cpuinfo_arm_chipset_series_renesas_mp] = "MP", |
| 3215 | [cpuinfo_arm_chipset_series_rockchip_rk] = "RK", |
| 3216 | [cpuinfo_arm_chipset_series_spreadtrum_sc] = "SC", |
| 3217 | [cpuinfo_arm_chipset_series_telechips_tcc] = "TCC", |
| 3218 | [cpuinfo_arm_chipset_series_texas_instruments_omap] = "OMAP", |
| 3219 | [cpuinfo_arm_chipset_series_wondermedia_wm] = "WM", |
| 3220 | }; |
| 3221 | |
| 3222 | /* Convert chipset name represented by cpuinfo_arm_chipset structure to a string representation */ |
| 3223 | void cpuinfo_arm_chipset_to_string( |
| 3224 | const struct cpuinfo_arm_chipset chipset[restrict static 1], |
| 3225 | char name[restrict static CPUINFO_ARM_CHIPSET_NAME_MAX]) |
| 3226 | { |
| 3227 | enum cpuinfo_arm_chipset_vendor vendor = chipset->vendor; |
| 3228 | if (vendor >= cpuinfo_arm_chipset_vendor_max) { |
| 3229 | vendor = cpuinfo_arm_chipset_vendor_unknown; |
| 3230 | } |
| 3231 | enum cpuinfo_arm_chipset_series series = chipset->series; |
| 3232 | if (series >= cpuinfo_arm_chipset_series_max) { |
| 3233 | series = cpuinfo_arm_chipset_series_unknown; |
| 3234 | } |
| 3235 | const char* vendor_string = chipset_vendor_string[vendor]; |
| 3236 | const char* series_string = chipset_series_string[series]; |
| 3237 | const uint32_t model = chipset->model; |
| 3238 | if (model == 0) { |
| 3239 | if (series == cpuinfo_arm_chipset_series_unknown) { |
| 3240 | strncpy(name, vendor_string, CPUINFO_ARM_CHIPSET_NAME_MAX); |
| 3241 | } else { |
| 3242 | snprintf(name, CPUINFO_ARM_CHIPSET_NAME_MAX, |
| 3243 | "%s %s", vendor_string, series_string); |
| 3244 | } |
| 3245 | } else { |
| 3246 | const size_t suffix_length = strnlen(chipset->suffix, CPUINFO_ARM_CHIPSET_SUFFIX_MAX); |
| 3247 | snprintf(name, CPUINFO_ARM_CHIPSET_NAME_MAX, |
| 3248 | "%s %s%"PRIu32"%.*s", vendor_string, series_string, model, (int) suffix_length, chipset->suffix); |
| 3249 | } |
| 3250 | } |
| 3251 | |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 3252 | #ifdef __ANDROID__ |
| 3253 | static inline struct cpuinfo_arm_chipset disambiguate_qualcomm_chipset( |
| 3254 | const struct cpuinfo_arm_chipset proc_cpuinfo_hardware_chipset[restrict static 1], |
| 3255 | const struct cpuinfo_arm_chipset ro_product_board_chipset[restrict static 1], |
| 3256 | const struct cpuinfo_arm_chipset ro_board_platform_chipset[restrict static 1], |
| 3257 | const struct cpuinfo_arm_chipset ro_chipname_chipset[restrict static 1]) |
| 3258 | { |
| 3259 | if (ro_chipname_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3260 | return *ro_chipname_chipset; |
| 3261 | } |
| 3262 | if (proc_cpuinfo_hardware_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3263 | return *proc_cpuinfo_hardware_chipset; |
| 3264 | } |
| 3265 | if (ro_product_board_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3266 | return *ro_product_board_chipset; |
| 3267 | } |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 3268 | return *ro_board_platform_chipset; |
| 3269 | } |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 3270 | |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 3271 | static inline struct cpuinfo_arm_chipset disambiguate_mediatek_chipset( |
| 3272 | const struct cpuinfo_arm_chipset proc_cpuinfo_hardware_chipset[restrict static 1], |
| 3273 | const struct cpuinfo_arm_chipset ro_product_board_chipset[restrict static 1], |
| 3274 | const struct cpuinfo_arm_chipset ro_board_platform_chipset[restrict static 1], |
| 3275 | const struct cpuinfo_arm_chipset ro_mediatek_platform_chipset[restrict static 1], |
| 3276 | const struct cpuinfo_arm_chipset ro_chipname_chipset[restrict static 1]) |
| 3277 | { |
| 3278 | if (ro_chipname_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3279 | return *ro_chipname_chipset; |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 3280 | } |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 3281 | if (proc_cpuinfo_hardware_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3282 | return *proc_cpuinfo_hardware_chipset; |
| 3283 | } |
| 3284 | if (ro_product_board_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3285 | return *ro_product_board_chipset; |
| 3286 | } |
| 3287 | if (ro_board_platform_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3288 | return *ro_board_platform_chipset; |
| 3289 | } |
| 3290 | return *ro_mediatek_platform_chipset; |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 3291 | } |
| 3292 | |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 3293 | static inline struct cpuinfo_arm_chipset disambiguate_hisilicon_chipset( |
| 3294 | const struct cpuinfo_arm_chipset proc_cpuinfo_hardware_chipset[restrict static 1], |
| 3295 | const struct cpuinfo_arm_chipset ro_product_board_chipset[restrict static 1], |
| 3296 | const struct cpuinfo_arm_chipset ro_board_platform_chipset[restrict static 1]) |
| 3297 | { |
| 3298 | if (proc_cpuinfo_hardware_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3299 | return *proc_cpuinfo_hardware_chipset; |
| 3300 | } |
| 3301 | if (ro_product_board_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3302 | return *ro_product_board_chipset; |
| 3303 | } |
| 3304 | return *ro_board_platform_chipset; |
| 3305 | } |
| 3306 | |
| 3307 | static inline struct cpuinfo_arm_chipset disambiguate_amlogic_chipset( |
| 3308 | const struct cpuinfo_arm_chipset proc_cpuinfo_hardware_chipset[restrict static 1], |
| 3309 | const struct cpuinfo_arm_chipset ro_board_platform_chipset[restrict static 1]) |
| 3310 | { |
| 3311 | if (proc_cpuinfo_hardware_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3312 | return *proc_cpuinfo_hardware_chipset; |
| 3313 | } |
| 3314 | return *ro_board_platform_chipset; |
| 3315 | } |
| 3316 | |
| 3317 | static inline struct cpuinfo_arm_chipset disambiguate_marvell_chipset( |
| 3318 | const struct cpuinfo_arm_chipset proc_cpuinfo_hardware_chipset[restrict static 1], |
| 3319 | const struct cpuinfo_arm_chipset ro_product_board_chipset[restrict static 1], |
| 3320 | const struct cpuinfo_arm_chipset ro_chipname_chipset[restrict static 1]) |
| 3321 | { |
| 3322 | if (ro_chipname_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3323 | return *ro_chipname_chipset; |
| 3324 | } |
| 3325 | if (ro_product_board_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3326 | return *ro_product_board_chipset; |
| 3327 | } |
| 3328 | return *proc_cpuinfo_hardware_chipset; |
| 3329 | } |
| 3330 | |
| 3331 | static inline struct cpuinfo_arm_chipset disambiguate_rockchip_chipset( |
| 3332 | const struct cpuinfo_arm_chipset proc_cpuinfo_hardware_chipset[restrict static 1], |
| 3333 | const struct cpuinfo_arm_chipset ro_product_board_chipset[restrict static 1], |
| 3334 | const struct cpuinfo_arm_chipset ro_board_platform_chipset[restrict static 1]) |
| 3335 | { |
| 3336 | if (ro_product_board_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3337 | return *ro_product_board_chipset; |
| 3338 | } |
| 3339 | if (proc_cpuinfo_hardware_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3340 | return *proc_cpuinfo_hardware_chipset; |
| 3341 | } |
| 3342 | return *ro_board_platform_chipset; |
| 3343 | } |
| 3344 | |
| 3345 | static inline struct cpuinfo_arm_chipset disambiguate_spreadtrum_chipset( |
| 3346 | const struct cpuinfo_arm_chipset proc_cpuinfo_hardware_chipset[restrict static 1], |
| 3347 | const struct cpuinfo_arm_chipset ro_product_board_chipset[restrict static 1], |
| 3348 | const struct cpuinfo_arm_chipset ro_board_platform_chipset[restrict static 1], |
| 3349 | const struct cpuinfo_arm_chipset ro_chipname_chipset[restrict static 1]) |
| 3350 | { |
| 3351 | if (ro_chipname_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3352 | return *ro_chipname_chipset; |
| 3353 | } |
| 3354 | if (ro_product_board_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3355 | return *ro_product_board_chipset; |
| 3356 | } |
| 3357 | if (proc_cpuinfo_hardware_chipset->series != cpuinfo_arm_chipset_series_unknown) { |
| 3358 | return *proc_cpuinfo_hardware_chipset; |
| 3359 | } |
| 3360 | return *ro_board_platform_chipset; |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 3361 | } |
| 3362 | |
| 3363 | /* |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 3364 | * Decodes chipset name from Android system properties: |
| 3365 | * - /proc/cpuinfo Hardware string |
| 3366 | * - ro.product.board |
| 3367 | * - ro.board.platform |
| 3368 | * - ro.mediatek.platform |
| 3369 | * - ro.chipname |
| 3370 | * For some chipsets, the function relies frequency and on number of cores for chipset detection. |
| 3371 | * |
| 3372 | * @param[in] properties - structure with the Android system properties described above. |
| 3373 | * @param cores - number of cores in the chipset. |
| 3374 | * @param max_cpu_freq_max - maximum of /sys/devices/system/cpu/cpu<number>/cpofreq/cpu_freq_max values. |
| 3375 | * |
| 3376 | * @returns Decoded chipset name. If chipset could not be decoded, the resulting structure would use `unknown` vendor |
| 3377 | * and series identifiers. |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 3378 | */ |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 3379 | struct cpuinfo_arm_chipset cpuinfo_arm_android_decode_chipset( |
| 3380 | const struct cpuinfo_android_properties properties[restrict static 1], |
| 3381 | uint32_t cores, |
| 3382 | uint32_t max_cpu_freq_max) |
| 3383 | { |
| 3384 | struct cpuinfo_arm_chipset chipset = { |
| 3385 | .vendor = cpuinfo_arm_chipset_vendor_unknown, |
| 3386 | .series = cpuinfo_arm_chipset_series_unknown, |
| 3387 | }; |
| 3388 | |
| 3389 | const bool tegra_platform = is_tegra( |
| 3390 | properties->ro_board_platform, |
| 3391 | properties->ro_board_platform + strnlen(properties->ro_board_platform, CPUINFO_BUILD_PROP_VALUE_MAX)); |
| 3392 | |
| 3393 | struct cpuinfo_arm_chipset chipsets[cpuinfo_android_chipset_property_max] = { |
| 3394 | [cpuinfo_android_chipset_property_proc_cpuinfo_hardware] = |
Marat Dukhan | 1415d7d | 2017-10-16 09:40:15 -0700 | [diff] [blame] | 3395 | cpuinfo_arm_linux_decode_chipset_from_proc_cpuinfo_hardware( |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 3396 | properties->proc_cpuinfo_hardware, cores, max_cpu_freq_max, tegra_platform), |
| 3397 | [cpuinfo_android_chipset_property_ro_product_board] = |
| 3398 | cpuinfo_arm_android_decode_chipset_from_ro_product_board( |
| 3399 | properties->ro_product_board, cores, max_cpu_freq_max), |
| 3400 | [cpuinfo_android_chipset_property_ro_board_platform] = |
| 3401 | cpuinfo_arm_android_decode_chipset_from_ro_board_platform( |
| 3402 | properties->ro_board_platform, cores, max_cpu_freq_max), |
| 3403 | [cpuinfo_android_chipset_property_ro_mediatek_platform] = |
| 3404 | cpuinfo_arm_android_decode_chipset_from_ro_mediatek_platform(properties->ro_mediatek_platform), |
Marat Dukhan | e5d6049 | 2018-03-08 12:47:27 -0800 | [diff] [blame] | 3405 | [cpuinfo_android_chipset_property_ro_arch] = |
| 3406 | cpuinfo_arm_android_decode_chipset_from_ro_arch(properties->ro_arch), |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 3407 | [cpuinfo_android_chipset_property_ro_chipname] = |
| 3408 | cpuinfo_arm_android_decode_chipset_from_ro_chipname(properties->ro_chipname), |
| 3409 | }; |
| 3410 | enum cpuinfo_arm_chipset_vendor vendor = cpuinfo_arm_chipset_vendor_unknown; |
| 3411 | for (size_t i = 0; i < cpuinfo_android_chipset_property_max; i++) { |
| 3412 | const enum cpuinfo_arm_chipset_vendor decoded_vendor = chipsets[i].vendor; |
| 3413 | if (decoded_vendor != cpuinfo_arm_chipset_vendor_unknown) { |
| 3414 | if (vendor == cpuinfo_arm_chipset_vendor_unknown) { |
| 3415 | vendor = decoded_vendor; |
| 3416 | } else if (vendor != decoded_vendor) { |
| 3417 | /* Parsing different system properties produces different chipset vendors. This situation is rare. */ |
| 3418 | cpuinfo_log_error( |
| 3419 | "chipset detection failed: different chipset vendors reported in different system properties"); |
| 3420 | goto finish; |
| 3421 | } |
| 3422 | } |
| 3423 | } |
| 3424 | if (vendor == cpuinfo_arm_chipset_vendor_unknown) { |
| 3425 | cpuinfo_log_warning( |
| 3426 | "chipset detection failed: none of the system properties matched known signatures"); |
| 3427 | goto finish; |
| 3428 | } |
| 3429 | |
| 3430 | /* Fix common bugs in reported chipsets */ |
| 3431 | for (size_t i = 0; i < cpuinfo_android_chipset_property_max; i++) { |
| 3432 | cpuinfo_arm_fixup_chipset(&chipsets[i], cores, max_cpu_freq_max); |
| 3433 | } |
| 3434 | |
| 3435 | /* |
| 3436 | * Propagate suffixes: consider all pairs of chipsets, if both chipsets in the pair are from the same series, |
| 3437 | * and one's suffix is a prefix of another's chipset suffix, use the longest suffix. |
| 3438 | */ |
| 3439 | for (size_t i = 0; i < cpuinfo_android_chipset_property_max; i++) { |
| 3440 | const size_t chipset_i_suffix_length = strnlen(chipsets[i].suffix, CPUINFO_ARM_CHIPSET_SUFFIX_MAX); |
| 3441 | for (size_t j = 0; j < i; j++) { |
| 3442 | if (chipsets[i].series == chipsets[j].series) { |
| 3443 | const size_t chipset_j_suffix_length = strnlen(chipsets[j].suffix, CPUINFO_ARM_CHIPSET_SUFFIX_MAX); |
| 3444 | if (chipset_i_suffix_length != chipset_j_suffix_length) { |
| 3445 | const size_t common_prefix_length = (chipset_i_suffix_length < chipset_j_suffix_length) ? |
| 3446 | chipset_i_suffix_length : chipset_j_suffix_length; |
| 3447 | if (common_prefix_length == 0 || |
| 3448 | memcmp(chipsets[i].suffix, chipsets[j].suffix, common_prefix_length) == 0) |
| 3449 | { |
| 3450 | if (chipset_i_suffix_length > chipset_j_suffix_length) { |
| 3451 | memcpy(chipsets[j].suffix, chipsets[i].suffix, chipset_i_suffix_length); |
| 3452 | } else { |
| 3453 | memcpy(chipsets[i].suffix, chipsets[j].suffix, chipset_j_suffix_length); |
| 3454 | } |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 3455 | } |
| 3456 | } |
| 3457 | } |
| 3458 | } |
| 3459 | } |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 3460 | |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 3461 | for (size_t i = 0; i < cpuinfo_android_chipset_property_max; i++) { |
| 3462 | if (chipsets[i].series != cpuinfo_arm_chipset_series_unknown) { |
| 3463 | if (chipset.series == cpuinfo_arm_chipset_series_unknown) { |
| 3464 | chipset = chipsets[i]; |
| 3465 | } else if (chipsets[i].series != chipset.series || chipsets[i].model != chipset.model || |
| 3466 | strncmp(chipsets[i].suffix, chipset.suffix, CPUINFO_ARM_CHIPSET_SUFFIX_MAX) != 0) |
| 3467 | { |
| 3468 | cpuinfo_log_info( |
| 3469 | "different chipsets reported in different system properties; " |
| 3470 | "vendor-specific disambiguation heuristic would be used"); |
| 3471 | switch (vendor) { |
| 3472 | case cpuinfo_arm_chipset_vendor_qualcomm: |
| 3473 | return disambiguate_qualcomm_chipset( |
| 3474 | &chipsets[cpuinfo_android_chipset_property_proc_cpuinfo_hardware], |
| 3475 | &chipsets[cpuinfo_android_chipset_property_ro_product_board], |
| 3476 | &chipsets[cpuinfo_android_chipset_property_ro_board_platform], |
| 3477 | &chipsets[cpuinfo_android_chipset_property_ro_chipname]); |
| 3478 | case cpuinfo_arm_chipset_vendor_mediatek: |
| 3479 | return disambiguate_mediatek_chipset( |
| 3480 | &chipsets[cpuinfo_android_chipset_property_proc_cpuinfo_hardware], |
| 3481 | &chipsets[cpuinfo_android_chipset_property_ro_product_board], |
| 3482 | &chipsets[cpuinfo_android_chipset_property_ro_board_platform], |
| 3483 | &chipsets[cpuinfo_android_chipset_property_ro_mediatek_platform], |
| 3484 | &chipsets[cpuinfo_android_chipset_property_ro_chipname]); |
| 3485 | case cpuinfo_arm_chipset_vendor_hisilicon: |
| 3486 | return disambiguate_hisilicon_chipset( |
| 3487 | &chipsets[cpuinfo_android_chipset_property_proc_cpuinfo_hardware], |
| 3488 | &chipsets[cpuinfo_android_chipset_property_ro_product_board], |
| 3489 | &chipsets[cpuinfo_android_chipset_property_ro_board_platform]); |
| 3490 | case cpuinfo_arm_chipset_vendor_amlogic: |
| 3491 | return disambiguate_amlogic_chipset( |
| 3492 | &chipsets[cpuinfo_android_chipset_property_proc_cpuinfo_hardware], |
| 3493 | &chipsets[cpuinfo_android_chipset_property_ro_board_platform]); |
| 3494 | case cpuinfo_arm_chipset_vendor_marvell: |
| 3495 | return disambiguate_marvell_chipset( |
| 3496 | &chipsets[cpuinfo_android_chipset_property_proc_cpuinfo_hardware], |
| 3497 | &chipsets[cpuinfo_android_chipset_property_ro_product_board], |
| 3498 | &chipsets[cpuinfo_android_chipset_property_ro_chipname]); |
| 3499 | case cpuinfo_arm_chipset_vendor_rockchip: |
| 3500 | return disambiguate_rockchip_chipset( |
| 3501 | &chipsets[cpuinfo_android_chipset_property_proc_cpuinfo_hardware], |
| 3502 | &chipsets[cpuinfo_android_chipset_property_ro_product_board], |
| 3503 | &chipsets[cpuinfo_android_chipset_property_ro_board_platform]); |
| 3504 | case cpuinfo_arm_chipset_vendor_spreadtrum: |
| 3505 | return disambiguate_spreadtrum_chipset( |
| 3506 | &chipsets[cpuinfo_android_chipset_property_proc_cpuinfo_hardware], |
| 3507 | &chipsets[cpuinfo_android_chipset_property_ro_product_board], |
| 3508 | &chipsets[cpuinfo_android_chipset_property_ro_board_platform], |
| 3509 | &chipsets[cpuinfo_android_chipset_property_ro_chipname]); |
| 3510 | default: |
| 3511 | cpuinfo_log_error( |
| 3512 | "chipset detection failed: " |
| 3513 | "could not disambiguate different chipsets reported in different system properties"); |
| 3514 | /* chipset variable contains valid, but inconsistent chipset information, overwrite it */ |
| 3515 | chipset = (struct cpuinfo_arm_chipset) { |
| 3516 | .vendor = cpuinfo_arm_chipset_vendor_unknown, |
| 3517 | .series = cpuinfo_arm_chipset_series_unknown, |
| 3518 | }; |
| 3519 | goto finish; |
| 3520 | } |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 3521 | } |
| 3522 | } |
| 3523 | } |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 3524 | |
| 3525 | finish: |
| 3526 | return chipset; |
| 3527 | } |
| 3528 | #else /* !defined(__ANDROID__) */ |
| 3529 | |
| 3530 | /* |
| 3531 | * Decodes chipset name from /proc/cpuinfo Hardware string. |
| 3532 | * For some chipsets, the function relies frequency and on number of cores for chipset detection. |
| 3533 | * |
| 3534 | * @param[in] hardware - /proc/cpuinfo Hardware string. |
| 3535 | * @param cores - number of cores in the chipset. |
| 3536 | * @param max_cpu_freq_max - maximum of /sys/devices/system/cpu/cpu<number>/cpofreq/cpu_freq_max values. |
| 3537 | * |
| 3538 | * @returns Decoded chipset name. If chipset could not be decoded, the resulting structure would use `unknown` vendor |
| 3539 | * and series identifiers. |
| 3540 | */ |
| 3541 | struct cpuinfo_arm_chipset cpuinfo_arm_linux_decode_chipset( |
| 3542 | const char hardware[restrict static CPUINFO_HARDWARE_VALUE_MAX], |
| 3543 | uint32_t cores, |
| 3544 | uint32_t max_cpu_freq_max) |
| 3545 | { |
| 3546 | struct cpuinfo_arm_chipset chipset = |
Marat Dukhan | 1415d7d | 2017-10-16 09:40:15 -0700 | [diff] [blame] | 3547 | cpuinfo_arm_linux_decode_chipset_from_proc_cpuinfo_hardware( |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 3548 | hardware, cores, max_cpu_freq_max, false); |
| 3549 | if (chipset.vendor == cpuinfo_arm_chipset_vendor_unknown) { |
| 3550 | cpuinfo_log_warning( |
| 3551 | "chipset detection failed: /proc/cpuinfo Hardware string did not match known signatures"); |
| 3552 | } else { |
| 3553 | cpuinfo_arm_fixup_chipset(&chipset, cores, max_cpu_freq_max); |
| 3554 | } |
| 3555 | return chipset; |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 3556 | } |
| 3557 | |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 3558 | #endif |