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