Ben Tyner | 92e39fd | 2020-02-05 18:11:02 -0600 | [diff] [blame] | 1 | /** |
Ben Tyner | b859d79 | 2020-05-06 21:29:47 -0500 | [diff] [blame] | 2 | * @file These are the implementations of the user interfaces declared |
| 3 | * in hei_user_interface.hpp |
Ben Tyner | 92e39fd | 2020-02-05 18:11:02 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
Ben Tyner | b859d79 | 2020-05-06 21:29:47 -0500 | [diff] [blame] | 6 | #include <assert.h> |
Ben Tyner | 0523f8a | 2020-05-14 16:01:53 -0500 | [diff] [blame] | 7 | #include <inttypes.h> |
| 8 | #include <libpdbg.h> |
Zane Shelley | b78dd0c | 2020-05-08 14:35:15 -0500 | [diff] [blame] | 9 | #include <stdarg.h> |
| 10 | #include <stdio.h> |
| 11 | |
Ben Tyner | 92e39fd | 2020-02-05 18:11:02 -0600 | [diff] [blame] | 12 | #include <hei_user_interface.hpp> |
Zane Shelley | 0c44c2f | 2020-06-05 17:14:31 -0500 | [diff] [blame] | 13 | #include <util/trace.hpp> |
Ben Tyner | 92e39fd | 2020-02-05 18:11:02 -0600 | [diff] [blame] | 14 | |
| 15 | namespace libhei |
| 16 | { |
| 17 | |
Zane Shelley | 06e10f9 | 2020-08-10 20:35:08 -0500 | [diff] [blame] | 18 | const char* __regType(RegisterType_t i_regType) |
| 19 | { |
| 20 | const char* str = ""; |
| 21 | switch (i_regType) |
| 22 | { |
| 23 | case REG_TYPE_SCOM: |
| 24 | str = "SCOM"; |
| 25 | break; |
| 26 | case REG_TYPE_ID_SCOM: |
| 27 | str = "ID_SCOM"; |
| 28 | break; |
| 29 | default: |
| 30 | trace::err("Unsupported register type: i_regType=0x%02x", |
| 31 | i_regType); |
| 32 | assert(0); |
| 33 | } |
| 34 | return str; |
| 35 | } |
| 36 | |
| 37 | //------------------------------------------------------------------------------ |
| 38 | |
| 39 | bool __readProc(pdbg_target* i_procTrgt, RegisterType_t i_regType, |
| 40 | uint64_t i_address, uint64_t& o_value) |
| 41 | { |
| 42 | bool accessFailure = false; |
| 43 | |
| 44 | // The processor PIB target is required for SCOM access. |
| 45 | char path[16]; |
| 46 | sprintf(path, "/proc%d/pib", pdbg_target_index(i_procTrgt)); |
| 47 | pdbg_target* scomTrgt = pdbg_target_from_path(nullptr, path); |
| 48 | assert(nullptr != scomTrgt); |
| 49 | |
| 50 | switch (i_regType) |
| 51 | { |
| 52 | case REG_TYPE_SCOM: |
| 53 | case REG_TYPE_ID_SCOM: |
| 54 | // Read the 64-bit SCOM register. |
| 55 | accessFailure = (0 != pib_read(scomTrgt, i_address, &o_value)); |
| 56 | break; |
| 57 | |
| 58 | default: |
| 59 | trace::err("Unsupported register type: trgt=%s regType=0x%02x " |
| 60 | "addr=0x%0" PRIx64, |
| 61 | pdbg_target_path(i_procTrgt), i_regType, i_address); |
| 62 | assert(0); // an unsupported register type |
| 63 | } |
| 64 | |
| 65 | return accessFailure; |
| 66 | } |
| 67 | |
| 68 | //------------------------------------------------------------------------------ |
| 69 | |
| 70 | bool __readOcmb(pdbg_target* i_obmcTrgt, RegisterType_t i_regType, |
| 71 | uint64_t i_address, uint64_t& o_value) |
| 72 | { |
| 73 | bool accessFailure = false; |
| 74 | |
| 75 | /* TODO: ocmb_getscom() currently does not exist upstream. |
| 76 | // The OCMB target is used for SCOM access. |
| 77 | pdbg_target* scomTrgt = i_obmcTrgt; |
| 78 | |
| 79 | switch (i_regType) |
| 80 | { |
| 81 | case REG_TYPE_SCOM: |
| 82 | case REG_TYPE_ID_SCOM: |
| 83 | // Read the 64-bit SCOM register. |
| 84 | accessFailure = (0 != ocmb_getscom(scomTrgt, i_address, &o_value)); |
| 85 | break; |
| 86 | |
| 87 | default: |
| 88 | trace::err("Unsupported register type: trgt=%s regType=0x%02x " |
| 89 | "addr=0x%0" PRIx64, |
| 90 | pdbg_target_path(i_obmcTrgt), i_regType, i_address); |
| 91 | assert(0); |
| 92 | } |
| 93 | */ |
| 94 | |
| 95 | return accessFailure; |
| 96 | } |
| 97 | |
Ben Tyner | 92e39fd | 2020-02-05 18:11:02 -0600 | [diff] [blame] | 98 | //------------------------------------------------------------------------------ |
| 99 | |
Ben Tyner | 0523f8a | 2020-05-14 16:01:53 -0500 | [diff] [blame] | 100 | bool registerRead(const Chip& i_chip, RegisterType_t i_regType, |
| 101 | uint64_t i_address, uint64_t& o_value) |
Ben Tyner | 92e39fd | 2020-02-05 18:11:02 -0600 | [diff] [blame] | 102 | { |
Zane Shelley | b78dd0c | 2020-05-08 14:35:15 -0500 | [diff] [blame] | 103 | bool accessFailure = false; |
Ben Tyner | 92e39fd | 2020-02-05 18:11:02 -0600 | [diff] [blame] | 104 | |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 105 | auto trgt = (pdbg_target*)(i_chip.getChip()); |
| 106 | |
Zane Shelley | 06e10f9 | 2020-08-10 20:35:08 -0500 | [diff] [blame] | 107 | uint8_t trgtType = 0; |
| 108 | pdbg_target_get_attribute(trgt, "ATTR_TYPE", 1, 1, &trgtType); |
| 109 | |
| 110 | switch (trgtType) |
Ben Tyner | 0523f8a | 2020-05-14 16:01:53 -0500 | [diff] [blame] | 111 | { |
Zane Shelley | 06e10f9 | 2020-08-10 20:35:08 -0500 | [diff] [blame] | 112 | case 0x05: // PROC |
| 113 | accessFailure = __readProc(trgt, i_regType, i_address, o_value); |
| 114 | break; |
| 115 | |
| 116 | case 0x4b: // OCMB_CHIP |
| 117 | accessFailure = __readOcmb(trgt, i_regType, i_address, o_value); |
Ben Tyner | 0523f8a | 2020-05-14 16:01:53 -0500 | [diff] [blame] | 118 | break; |
Ben Tyner | b859d79 | 2020-05-06 21:29:47 -0500 | [diff] [blame] | 119 | |
Ben Tyner | 0523f8a | 2020-05-14 16:01:53 -0500 | [diff] [blame] | 120 | default: |
Zane Shelley | 06e10f9 | 2020-08-10 20:35:08 -0500 | [diff] [blame] | 121 | trace::err("Unsupported target type: trgt=%s trgtType=0x%02x", |
| 122 | pdbg_target_path(trgt), trgtType); |
| 123 | assert(0); |
Ben Tyner | 0523f8a | 2020-05-14 16:01:53 -0500 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | if (accessFailure) |
| 127 | { |
Zane Shelley | 06e10f9 | 2020-08-10 20:35:08 -0500 | [diff] [blame] | 128 | trace::err("%s failure: trgt=%s addr=0x%0" PRIx64, __regType(i_regType), |
| 129 | pdbg_target_path(trgt), i_address); |
Ben Tyner | 0523f8a | 2020-05-14 16:01:53 -0500 | [diff] [blame] | 130 | o_value = 0; // just in case |
| 131 | } |
Ben Tyner | 92e39fd | 2020-02-05 18:11:02 -0600 | [diff] [blame] | 132 | |
Zane Shelley | b78dd0c | 2020-05-08 14:35:15 -0500 | [diff] [blame] | 133 | return accessFailure; |
Ben Tyner | 92e39fd | 2020-02-05 18:11:02 -0600 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | //------------------------------------------------------------------------------ |
| 137 | |
Zane Shelley | b78dd0c | 2020-05-08 14:35:15 -0500 | [diff] [blame] | 138 | // prints a single line to stdout |
| 139 | void hei_inf(char* format, ...) |
| 140 | { |
| 141 | va_list args; |
Zane Shelley | b78dd0c | 2020-05-08 14:35:15 -0500 | [diff] [blame] | 142 | va_start(args, format); |
Zane Shelley | 0c44c2f | 2020-06-05 17:14:31 -0500 | [diff] [blame] | 143 | trace::inf(format, args); |
Zane Shelley | b78dd0c | 2020-05-08 14:35:15 -0500 | [diff] [blame] | 144 | va_end(args); |
Zane Shelley | b78dd0c | 2020-05-08 14:35:15 -0500 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | //------------------------------------------------------------------------------ |
| 148 | |
| 149 | // prints a single line to stderr |
| 150 | void hei_err(char* format, ...) |
| 151 | { |
| 152 | va_list args; |
Zane Shelley | b78dd0c | 2020-05-08 14:35:15 -0500 | [diff] [blame] | 153 | va_start(args, format); |
Zane Shelley | 0c44c2f | 2020-06-05 17:14:31 -0500 | [diff] [blame] | 154 | trace::err(format, args); |
Zane Shelley | b78dd0c | 2020-05-08 14:35:15 -0500 | [diff] [blame] | 155 | va_end(args); |
Zane Shelley | b78dd0c | 2020-05-08 14:35:15 -0500 | [diff] [blame] | 156 | } |
| 157 | |
Ben Tyner | 92e39fd | 2020-02-05 18:11:02 -0600 | [diff] [blame] | 158 | } // namespace libhei |