Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 1 | #include <stdbool.h> |
| 2 | #include <stdint.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <stddef.h> |
| 5 | #include <string.h> |
| 6 | |
Marat Dukhan | 3c1df68 | 2017-09-22 17:09:49 -0700 | [diff] [blame] | 7 | #include <sys/system_properties.h> |
Marat Dukhan | d156525 | 2017-09-12 00:29:01 -0700 | [diff] [blame] | 8 | |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 9 | #include <linux/api.h> |
| 10 | #include <arm/android/api.h> |
| 11 | #include <arm/linux/api.h> |
Marat Dukhan | d0b3760 | 2018-12-09 01:59:26 -0800 | [diff] [blame] | 12 | #include <cpuinfo/log.h> |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 13 | |
Marat Dukhan | d156525 | 2017-09-12 00:29:01 -0700 | [diff] [blame] | 14 | #if CPUINFO_MOCK |
| 15 | #include <cpuinfo-mock.h> |
Marat Dukhan | d156525 | 2017-09-12 00:29:01 -0700 | [diff] [blame] | 16 | |
Marat Dukhan | d156525 | 2017-09-12 00:29:01 -0700 | [diff] [blame] | 17 | static struct cpuinfo_mock_property* cpuinfo_mock_properties = NULL; |
| 18 | |
| 19 | void CPUINFO_ABI cpuinfo_mock_android_properties(struct cpuinfo_mock_property* properties) { |
| 20 | cpuinfo_log_info("Android properties mocking enabled"); |
| 21 | cpuinfo_mock_properties = properties; |
| 22 | } |
| 23 | |
Marat Dukhan | 3c1df68 | 2017-09-22 17:09:49 -0700 | [diff] [blame] | 24 | static int cpuinfo_android_property_get(const char* key, char* value) { |
| 25 | if (cpuinfo_mock_properties != NULL) { |
| 26 | for (const struct cpuinfo_mock_property* prop = cpuinfo_mock_properties; prop->key != NULL; prop++) { |
| 27 | if (strncmp(key, prop->key, CPUINFO_BUILD_PROP_NAME_MAX) == 0) { |
| 28 | strncpy(value, prop->value, CPUINFO_BUILD_PROP_VALUE_MAX); |
| 29 | return (int) strnlen(prop->value, CPUINFO_BUILD_PROP_VALUE_MAX); |
| 30 | } |
Marat Dukhan | d156525 | 2017-09-12 00:29:01 -0700 | [diff] [blame] | 31 | } |
| 32 | } |
| 33 | *value = '\0'; |
| 34 | return 0; |
| 35 | } |
Marat Dukhan | d156525 | 2017-09-12 00:29:01 -0700 | [diff] [blame] | 36 | #else |
Marat Dukhan | 3c1df68 | 2017-09-22 17:09:49 -0700 | [diff] [blame] | 37 | static inline int cpuinfo_android_property_get(const char* key, char* value) { |
| 38 | return __system_property_get(key, value); |
Marat Dukhan | d156525 | 2017-09-12 00:29:01 -0700 | [diff] [blame] | 39 | } |
| 40 | #endif |
| 41 | |
Marat Dukhan | 3c1df68 | 2017-09-22 17:09:49 -0700 | [diff] [blame] | 42 | void cpuinfo_arm_android_parse_properties(struct cpuinfo_android_properties properties[restrict static 1]) { |
| 43 | const int ro_product_board_length = |
| 44 | cpuinfo_android_property_get("ro.product.board", properties->ro_product_board); |
| 45 | cpuinfo_log_debug("read ro.product.board = \"%.*s\"", ro_product_board_length, properties->ro_product_board); |
Marat Dukhan | d156525 | 2017-09-12 00:29:01 -0700 | [diff] [blame] | 46 | |
Marat Dukhan | 3c1df68 | 2017-09-22 17:09:49 -0700 | [diff] [blame] | 47 | const int ro_board_platform_length = |
| 48 | cpuinfo_android_property_get("ro.board.platform", properties->ro_board_platform); |
| 49 | cpuinfo_log_debug("read ro.board.platform = \"%.*s\"", ro_board_platform_length, properties->ro_board_platform); |
| 50 | |
| 51 | const int ro_mediatek_platform_length = |
| 52 | cpuinfo_android_property_get("ro.mediatek.platform", properties->ro_mediatek_platform); |
| 53 | cpuinfo_log_debug("read ro.mediatek.platform = \"%.*s\"", |
| 54 | ro_mediatek_platform_length, properties->ro_mediatek_platform); |
| 55 | |
Marat Dukhan | e5d6049 | 2018-03-08 12:47:27 -0800 | [diff] [blame] | 56 | const int ro_arch_length = |
| 57 | cpuinfo_android_property_get("ro.arch", properties->ro_arch); |
| 58 | cpuinfo_log_debug("read ro.arch = \"%.*s\"", ro_arch_length, properties->ro_arch); |
| 59 | |
Marat Dukhan | 3c1df68 | 2017-09-22 17:09:49 -0700 | [diff] [blame] | 60 | const int ro_chipname_length = |
| 61 | cpuinfo_android_property_get("ro.chipname", properties->ro_chipname); |
| 62 | cpuinfo_log_debug("read ro.chipname = \"%.*s\"", ro_chipname_length, properties->ro_chipname); |
Marat Dukhan | 006461a | 2017-08-24 16:10:46 -0700 | [diff] [blame] | 63 | } |