Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 1 | /* |
| 2 | * PS3 repository routines. |
| 3 | * |
| 4 | * Copyright (C) 2006 Sony Computer Entertainment Inc. |
| 5 | * Copyright 2006 Sony Corp. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 21 | #include <asm/lv1call.h> |
| 22 | |
Geoff Levand | 2a08ea6 | 2007-01-30 15:20:27 -0800 | [diff] [blame] | 23 | #include "platform.h" |
| 24 | |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 25 | enum ps3_vendor_id { |
| 26 | PS3_VENDOR_ID_NONE = 0, |
| 27 | PS3_VENDOR_ID_SONY = 0x8000000000000000UL, |
| 28 | }; |
| 29 | |
| 30 | enum ps3_lpar_id { |
| 31 | PS3_LPAR_ID_CURRENT = 0, |
| 32 | PS3_LPAR_ID_PME = 1, |
| 33 | }; |
| 34 | |
| 35 | #define dump_field(_a, _b) _dump_field(_a, _b, __func__, __LINE__) |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 36 | static void _dump_field(const char *hdr, u64 n, const char *func, int line) |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 37 | { |
| 38 | #if defined(DEBUG) |
| 39 | char s[16]; |
| 40 | const char *const in = (const char *)&n; |
| 41 | unsigned int i; |
| 42 | |
| 43 | for (i = 0; i < 8; i++) |
| 44 | s[i] = (in[i] <= 126 && in[i] >= 32) ? in[i] : '.'; |
| 45 | s[i] = 0; |
| 46 | |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 47 | pr_devel("%s:%d: %s%016llx : %s\n", func, line, hdr, n, s); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 48 | #endif |
| 49 | } |
| 50 | |
| 51 | #define dump_node_name(_a, _b, _c, _d, _e) \ |
| 52 | _dump_node_name(_a, _b, _c, _d, _e, __func__, __LINE__) |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 53 | static void _dump_node_name(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, |
| 54 | u64 n4, const char *func, int line) |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 55 | { |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 56 | pr_devel("%s:%d: lpar: %u\n", func, line, lpar_id); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 57 | _dump_field("n1: ", n1, func, line); |
| 58 | _dump_field("n2: ", n2, func, line); |
| 59 | _dump_field("n3: ", n3, func, line); |
| 60 | _dump_field("n4: ", n4, func, line); |
| 61 | } |
| 62 | |
| 63 | #define dump_node(_a, _b, _c, _d, _e, _f, _g) \ |
| 64 | _dump_node(_a, _b, _c, _d, _e, _f, _g, __func__, __LINE__) |
| 65 | static void _dump_node(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, u64 n4, |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 66 | u64 v1, u64 v2, const char *func, int line) |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 67 | { |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 68 | pr_devel("%s:%d: lpar: %u\n", func, line, lpar_id); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 69 | _dump_field("n1: ", n1, func, line); |
| 70 | _dump_field("n2: ", n2, func, line); |
| 71 | _dump_field("n3: ", n3, func, line); |
| 72 | _dump_field("n4: ", n4, func, line); |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 73 | pr_devel("%s:%d: v1: %016llx\n", func, line, v1); |
| 74 | pr_devel("%s:%d: v2: %016llx\n", func, line, v2); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /** |
| 78 | * make_first_field - Make the first field of a repository node name. |
| 79 | * @text: Text portion of the field. |
| 80 | * @index: Numeric index portion of the field. Use zero for 'don't care'. |
| 81 | * |
| 82 | * This routine sets the vendor id to zero (non-vendor specific). |
| 83 | * Returns field value. |
| 84 | */ |
| 85 | |
| 86 | static u64 make_first_field(const char *text, u64 index) |
| 87 | { |
| 88 | u64 n; |
| 89 | |
| 90 | strncpy((char *)&n, text, 8); |
| 91 | return PS3_VENDOR_ID_NONE + (n >> 32) + index; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * make_field - Make subsequent fields of a repository node name. |
| 96 | * @text: Text portion of the field. Use "" for 'don't care'. |
| 97 | * @index: Numeric index portion of the field. Use zero for 'don't care'. |
| 98 | * |
| 99 | * Returns field value. |
| 100 | */ |
| 101 | |
| 102 | static u64 make_field(const char *text, u64 index) |
| 103 | { |
| 104 | u64 n; |
| 105 | |
| 106 | strncpy((char *)&n, text, 8); |
| 107 | return n + index; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * read_node - Read a repository node from raw fields. |
| 112 | * @n1: First field of node name. |
| 113 | * @n2: Second field of node name. Use zero for 'don't care'. |
| 114 | * @n3: Third field of node name. Use zero for 'don't care'. |
| 115 | * @n4: Fourth field of node name. Use zero for 'don't care'. |
| 116 | * @v1: First repository value (high word). |
| 117 | * @v2: Second repository value (low word). Optional parameter, use zero |
| 118 | * for 'don't care'. |
| 119 | */ |
| 120 | |
| 121 | static int read_node(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, u64 n4, |
| 122 | u64 *_v1, u64 *_v2) |
| 123 | { |
| 124 | int result; |
| 125 | u64 v1; |
| 126 | u64 v2; |
| 127 | |
| 128 | if (lpar_id == PS3_LPAR_ID_CURRENT) { |
| 129 | u64 id; |
| 130 | lv1_get_logical_partition_id(&id); |
| 131 | lpar_id = id; |
| 132 | } |
| 133 | |
Geoff Levand | 7f8cd35 | 2011-11-29 15:38:50 +0000 | [diff] [blame] | 134 | result = lv1_read_repository_node(lpar_id, n1, n2, n3, n4, &v1, |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 135 | &v2); |
| 136 | |
| 137 | if (result) { |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 138 | pr_warn("%s:%d: lv1_read_repository_node failed: %s\n", |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 139 | __func__, __LINE__, ps3_result(result)); |
| 140 | dump_node_name(lpar_id, n1, n2, n3, n4); |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 141 | return -ENOENT; |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | dump_node(lpar_id, n1, n2, n3, n4, v1, v2); |
| 145 | |
| 146 | if (_v1) |
| 147 | *_v1 = v1; |
| 148 | if (_v2) |
| 149 | *_v2 = v2; |
| 150 | |
| 151 | if (v1 && !_v1) |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 152 | pr_devel("%s:%d: warning: discarding non-zero v1: %016llx\n", |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 153 | __func__, __LINE__, v1); |
| 154 | if (v2 && !_v2) |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 155 | pr_devel("%s:%d: warning: discarding non-zero v2: %016llx\n", |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 156 | __func__, __LINE__, v2); |
| 157 | |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 158 | return 0; |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | int ps3_repository_read_bus_str(unsigned int bus_index, const char *bus_str, |
| 162 | u64 *value) |
| 163 | { |
| 164 | return read_node(PS3_LPAR_ID_PME, |
| 165 | make_first_field("bus", bus_index), |
| 166 | make_field(bus_str, 0), |
| 167 | 0, 0, |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 168 | value, NULL); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 169 | } |
| 170 | |
Geert Uytterhoeven | 034e0ab | 2008-01-19 07:30:09 +1100 | [diff] [blame] | 171 | int ps3_repository_read_bus_id(unsigned int bus_index, u64 *bus_id) |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 172 | { |
| 173 | int result; |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 174 | |
| 175 | result = read_node(PS3_LPAR_ID_PME, |
| 176 | make_first_field("bus", bus_index), |
| 177 | make_field("id", 0), |
| 178 | 0, 0, |
Geert Uytterhoeven | 034e0ab | 2008-01-19 07:30:09 +1100 | [diff] [blame] | 179 | bus_id, NULL); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 180 | return result; |
| 181 | } |
| 182 | |
| 183 | int ps3_repository_read_bus_type(unsigned int bus_index, |
| 184 | enum ps3_bus_type *bus_type) |
| 185 | { |
| 186 | int result; |
Geoff Levand | 5233e26 | 2011-10-12 08:39:15 +0000 | [diff] [blame] | 187 | u64 v1 = 0; |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 188 | |
| 189 | result = read_node(PS3_LPAR_ID_PME, |
| 190 | make_first_field("bus", bus_index), |
| 191 | make_field("type", 0), |
| 192 | 0, 0, |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 193 | &v1, NULL); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 194 | *bus_type = v1; |
| 195 | return result; |
| 196 | } |
| 197 | |
| 198 | int ps3_repository_read_bus_num_dev(unsigned int bus_index, |
| 199 | unsigned int *num_dev) |
| 200 | { |
| 201 | int result; |
Geoff Levand | 5233e26 | 2011-10-12 08:39:15 +0000 | [diff] [blame] | 202 | u64 v1 = 0; |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 203 | |
| 204 | result = read_node(PS3_LPAR_ID_PME, |
| 205 | make_first_field("bus", bus_index), |
| 206 | make_field("num_dev", 0), |
| 207 | 0, 0, |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 208 | &v1, NULL); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 209 | *num_dev = v1; |
| 210 | return result; |
| 211 | } |
| 212 | |
| 213 | int ps3_repository_read_dev_str(unsigned int bus_index, |
| 214 | unsigned int dev_index, const char *dev_str, u64 *value) |
| 215 | { |
| 216 | return read_node(PS3_LPAR_ID_PME, |
| 217 | make_first_field("bus", bus_index), |
| 218 | make_field("dev", dev_index), |
| 219 | make_field(dev_str, 0), |
| 220 | 0, |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 221 | value, NULL); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | int ps3_repository_read_dev_id(unsigned int bus_index, unsigned int dev_index, |
Geert Uytterhoeven | 034e0ab | 2008-01-19 07:30:09 +1100 | [diff] [blame] | 225 | u64 *dev_id) |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 226 | { |
| 227 | int result; |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 228 | |
| 229 | result = read_node(PS3_LPAR_ID_PME, |
| 230 | make_first_field("bus", bus_index), |
| 231 | make_field("dev", dev_index), |
| 232 | make_field("id", 0), |
| 233 | 0, |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 234 | dev_id, NULL); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 235 | return result; |
| 236 | } |
| 237 | |
| 238 | int ps3_repository_read_dev_type(unsigned int bus_index, |
| 239 | unsigned int dev_index, enum ps3_dev_type *dev_type) |
| 240 | { |
| 241 | int result; |
Geoff Levand | 5233e26 | 2011-10-12 08:39:15 +0000 | [diff] [blame] | 242 | u64 v1 = 0; |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 243 | |
| 244 | result = read_node(PS3_LPAR_ID_PME, |
| 245 | make_first_field("bus", bus_index), |
| 246 | make_field("dev", dev_index), |
| 247 | make_field("type", 0), |
| 248 | 0, |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 249 | &v1, NULL); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 250 | *dev_type = v1; |
| 251 | return result; |
| 252 | } |
| 253 | |
| 254 | int ps3_repository_read_dev_intr(unsigned int bus_index, |
| 255 | unsigned int dev_index, unsigned int intr_index, |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 256 | enum ps3_interrupt_type *intr_type, unsigned int *interrupt_id) |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 257 | { |
| 258 | int result; |
Geoff Levand | 5233e26 | 2011-10-12 08:39:15 +0000 | [diff] [blame] | 259 | u64 v1 = 0; |
| 260 | u64 v2 = 0; |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 261 | |
| 262 | result = read_node(PS3_LPAR_ID_PME, |
| 263 | make_first_field("bus", bus_index), |
| 264 | make_field("dev", dev_index), |
| 265 | make_field("intr", intr_index), |
| 266 | 0, |
| 267 | &v1, &v2); |
| 268 | *intr_type = v1; |
| 269 | *interrupt_id = v2; |
| 270 | return result; |
| 271 | } |
| 272 | |
| 273 | int ps3_repository_read_dev_reg_type(unsigned int bus_index, |
Geoff Levand | eebb81c | 2007-01-26 19:07:47 -0800 | [diff] [blame] | 274 | unsigned int dev_index, unsigned int reg_index, |
| 275 | enum ps3_reg_type *reg_type) |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 276 | { |
| 277 | int result; |
Geoff Levand | 5233e26 | 2011-10-12 08:39:15 +0000 | [diff] [blame] | 278 | u64 v1 = 0; |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 279 | |
| 280 | result = read_node(PS3_LPAR_ID_PME, |
| 281 | make_first_field("bus", bus_index), |
| 282 | make_field("dev", dev_index), |
| 283 | make_field("reg", reg_index), |
| 284 | make_field("type", 0), |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 285 | &v1, NULL); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 286 | *reg_type = v1; |
| 287 | return result; |
| 288 | } |
| 289 | |
| 290 | int ps3_repository_read_dev_reg_addr(unsigned int bus_index, |
| 291 | unsigned int dev_index, unsigned int reg_index, u64 *bus_addr, u64 *len) |
| 292 | { |
| 293 | return read_node(PS3_LPAR_ID_PME, |
| 294 | make_first_field("bus", bus_index), |
| 295 | make_field("dev", dev_index), |
| 296 | make_field("reg", reg_index), |
| 297 | make_field("data", 0), |
| 298 | bus_addr, len); |
| 299 | } |
| 300 | |
| 301 | int ps3_repository_read_dev_reg(unsigned int bus_index, |
Geoff Levand | eebb81c | 2007-01-26 19:07:47 -0800 | [diff] [blame] | 302 | unsigned int dev_index, unsigned int reg_index, |
| 303 | enum ps3_reg_type *reg_type, u64 *bus_addr, u64 *len) |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 304 | { |
| 305 | int result = ps3_repository_read_dev_reg_type(bus_index, dev_index, |
| 306 | reg_index, reg_type); |
| 307 | return result ? result |
| 308 | : ps3_repository_read_dev_reg_addr(bus_index, dev_index, |
| 309 | reg_index, bus_addr, len); |
| 310 | } |
| 311 | |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 312 | |
| 313 | |
| 314 | int ps3_repository_find_device(struct ps3_repository_device *repo) |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 315 | { |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 316 | int result; |
| 317 | struct ps3_repository_device tmp = *repo; |
| 318 | unsigned int num_dev; |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 319 | |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 320 | BUG_ON(repo->bus_index > 10); |
| 321 | BUG_ON(repo->dev_index > 10); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 322 | |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 323 | result = ps3_repository_read_bus_num_dev(tmp.bus_index, &num_dev); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 324 | |
Geert Uytterhoeven | 6c7be7d | 2007-01-26 19:07:51 -0800 | [diff] [blame] | 325 | if (result) { |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 326 | pr_devel("%s:%d read_bus_num_dev failed\n", __func__, __LINE__); |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 327 | return result; |
Geert Uytterhoeven | 6c7be7d | 2007-01-26 19:07:51 -0800 | [diff] [blame] | 328 | } |
| 329 | |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 330 | pr_devel("%s:%d: bus_type %u, bus_index %u, bus_id %llu, num_dev %u\n", |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 331 | __func__, __LINE__, tmp.bus_type, tmp.bus_index, tmp.bus_id, |
| 332 | num_dev); |
Geert Uytterhoeven | 6c7be7d | 2007-01-26 19:07:51 -0800 | [diff] [blame] | 333 | |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 334 | if (tmp.dev_index >= num_dev) { |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 335 | pr_devel("%s:%d: no device found\n", __func__, __LINE__); |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 336 | return -ENODEV; |
Geert Uytterhoeven | 6c7be7d | 2007-01-26 19:07:51 -0800 | [diff] [blame] | 337 | } |
| 338 | |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 339 | result = ps3_repository_read_dev_type(tmp.bus_index, tmp.dev_index, |
| 340 | &tmp.dev_type); |
| 341 | |
| 342 | if (result) { |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 343 | pr_devel("%s:%d read_dev_type failed\n", __func__, __LINE__); |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 344 | return result; |
| 345 | } |
| 346 | |
| 347 | result = ps3_repository_read_dev_id(tmp.bus_index, tmp.dev_index, |
| 348 | &tmp.dev_id); |
| 349 | |
| 350 | if (result) { |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 351 | pr_devel("%s:%d ps3_repository_read_dev_id failed\n", __func__, |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 352 | __LINE__); |
| 353 | return result; |
| 354 | } |
| 355 | |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 356 | pr_devel("%s:%d: found: dev_type %u, dev_index %u, dev_id %llu\n", |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 357 | __func__, __LINE__, tmp.dev_type, tmp.dev_index, tmp.dev_id); |
| 358 | |
| 359 | *repo = tmp; |
| 360 | return 0; |
Geert Uytterhoeven | 6c7be7d | 2007-01-26 19:07:51 -0800 | [diff] [blame] | 361 | } |
| 362 | |
Geert Uytterhoeven | e06bcf3 | 2008-01-19 07:30:27 +1100 | [diff] [blame] | 363 | int ps3_repository_find_device_by_id(struct ps3_repository_device *repo, |
| 364 | u64 bus_id, u64 dev_id) |
| 365 | { |
| 366 | int result = -ENODEV; |
| 367 | struct ps3_repository_device tmp; |
| 368 | unsigned int num_dev; |
| 369 | |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 370 | pr_devel(" -> %s:%u: find device by id %llu:%llu\n", __func__, __LINE__, |
Geert Uytterhoeven | e06bcf3 | 2008-01-19 07:30:27 +1100 | [diff] [blame] | 371 | bus_id, dev_id); |
| 372 | |
| 373 | for (tmp.bus_index = 0; tmp.bus_index < 10; tmp.bus_index++) { |
| 374 | result = ps3_repository_read_bus_id(tmp.bus_index, |
| 375 | &tmp.bus_id); |
| 376 | if (result) { |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 377 | pr_devel("%s:%u read_bus_id(%u) failed\n", __func__, |
Geert Uytterhoeven | e06bcf3 | 2008-01-19 07:30:27 +1100 | [diff] [blame] | 378 | __LINE__, tmp.bus_index); |
| 379 | return result; |
| 380 | } |
| 381 | |
| 382 | if (tmp.bus_id == bus_id) |
| 383 | goto found_bus; |
| 384 | |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 385 | pr_devel("%s:%u: skip, bus_id %llu\n", __func__, __LINE__, |
Geert Uytterhoeven | e06bcf3 | 2008-01-19 07:30:27 +1100 | [diff] [blame] | 386 | tmp.bus_id); |
| 387 | } |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 388 | pr_devel(" <- %s:%u: bus not found\n", __func__, __LINE__); |
Geert Uytterhoeven | e06bcf3 | 2008-01-19 07:30:27 +1100 | [diff] [blame] | 389 | return result; |
| 390 | |
| 391 | found_bus: |
| 392 | result = ps3_repository_read_bus_type(tmp.bus_index, &tmp.bus_type); |
| 393 | if (result) { |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 394 | pr_devel("%s:%u read_bus_type(%u) failed\n", __func__, |
Geert Uytterhoeven | e06bcf3 | 2008-01-19 07:30:27 +1100 | [diff] [blame] | 395 | __LINE__, tmp.bus_index); |
| 396 | return result; |
| 397 | } |
| 398 | |
| 399 | result = ps3_repository_read_bus_num_dev(tmp.bus_index, &num_dev); |
| 400 | if (result) { |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 401 | pr_devel("%s:%u read_bus_num_dev failed\n", __func__, |
Geert Uytterhoeven | e06bcf3 | 2008-01-19 07:30:27 +1100 | [diff] [blame] | 402 | __LINE__); |
| 403 | return result; |
| 404 | } |
| 405 | |
| 406 | for (tmp.dev_index = 0; tmp.dev_index < num_dev; tmp.dev_index++) { |
| 407 | result = ps3_repository_read_dev_id(tmp.bus_index, |
| 408 | tmp.dev_index, |
| 409 | &tmp.dev_id); |
| 410 | if (result) { |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 411 | pr_devel("%s:%u read_dev_id(%u:%u) failed\n", __func__, |
Geert Uytterhoeven | e06bcf3 | 2008-01-19 07:30:27 +1100 | [diff] [blame] | 412 | __LINE__, tmp.bus_index, tmp.dev_index); |
| 413 | return result; |
| 414 | } |
| 415 | |
| 416 | if (tmp.dev_id == dev_id) |
| 417 | goto found_dev; |
| 418 | |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 419 | pr_devel("%s:%u: skip, dev_id %llu\n", __func__, __LINE__, |
Geert Uytterhoeven | e06bcf3 | 2008-01-19 07:30:27 +1100 | [diff] [blame] | 420 | tmp.dev_id); |
| 421 | } |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 422 | pr_devel(" <- %s:%u: dev not found\n", __func__, __LINE__); |
Geert Uytterhoeven | e06bcf3 | 2008-01-19 07:30:27 +1100 | [diff] [blame] | 423 | return result; |
| 424 | |
| 425 | found_dev: |
| 426 | result = ps3_repository_read_dev_type(tmp.bus_index, tmp.dev_index, |
| 427 | &tmp.dev_type); |
| 428 | if (result) { |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 429 | pr_devel("%s:%u read_dev_type failed\n", __func__, __LINE__); |
Geert Uytterhoeven | e06bcf3 | 2008-01-19 07:30:27 +1100 | [diff] [blame] | 430 | return result; |
| 431 | } |
| 432 | |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 433 | pr_devel(" <- %s:%u: found: type (%u:%u) index (%u:%u) id (%llu:%llu)\n", |
Geert Uytterhoeven | e06bcf3 | 2008-01-19 07:30:27 +1100 | [diff] [blame] | 434 | __func__, __LINE__, tmp.bus_type, tmp.dev_type, tmp.bus_index, |
| 435 | tmp.dev_index, tmp.bus_id, tmp.dev_id); |
| 436 | *repo = tmp; |
| 437 | return 0; |
| 438 | } |
| 439 | |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 440 | int __devinit ps3_repository_find_devices(enum ps3_bus_type bus_type, |
| 441 | int (*callback)(const struct ps3_repository_device *repo)) |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 442 | { |
| 443 | int result = 0; |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 444 | struct ps3_repository_device repo; |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 445 | |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 446 | pr_devel(" -> %s:%d: find bus_type %u\n", __func__, __LINE__, bus_type); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 447 | |
Geert Uytterhoeven | ad7d819 | 2008-01-19 07:32:10 +1100 | [diff] [blame] | 448 | repo.bus_type = bus_type; |
| 449 | result = ps3_repository_find_bus(repo.bus_type, 0, &repo.bus_index); |
| 450 | if (result) { |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 451 | pr_devel(" <- %s:%u: bus not found\n", __func__, __LINE__); |
Geert Uytterhoeven | ad7d819 | 2008-01-19 07:32:10 +1100 | [diff] [blame] | 452 | return result; |
| 453 | } |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 454 | |
Geert Uytterhoeven | ad7d819 | 2008-01-19 07:32:10 +1100 | [diff] [blame] | 455 | result = ps3_repository_read_bus_id(repo.bus_index, &repo.bus_id); |
| 456 | if (result) { |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 457 | pr_devel("%s:%d read_bus_id(%u) failed\n", __func__, __LINE__, |
Geert Uytterhoeven | ad7d819 | 2008-01-19 07:32:10 +1100 | [diff] [blame] | 458 | repo.bus_index); |
| 459 | return result; |
| 460 | } |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 461 | |
Geert Uytterhoeven | ad7d819 | 2008-01-19 07:32:10 +1100 | [diff] [blame] | 462 | for (repo.dev_index = 0; ; repo.dev_index++) { |
| 463 | result = ps3_repository_find_device(&repo); |
| 464 | if (result == -ENODEV) { |
| 465 | result = 0; |
| 466 | break; |
| 467 | } else if (result) |
| 468 | break; |
| 469 | |
| 470 | result = callback(&repo); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 471 | if (result) { |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 472 | pr_devel("%s:%d: abort at callback\n", __func__, |
Geert Uytterhoeven | ad7d819 | 2008-01-19 07:32:10 +1100 | [diff] [blame] | 473 | __LINE__); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 474 | break; |
| 475 | } |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 476 | } |
| 477 | |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 478 | pr_devel(" <- %s:%d\n", __func__, __LINE__); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 479 | return result; |
| 480 | } |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 481 | |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 482 | int ps3_repository_find_bus(enum ps3_bus_type bus_type, unsigned int from, |
| 483 | unsigned int *bus_index) |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 484 | { |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 485 | unsigned int i; |
| 486 | enum ps3_bus_type type; |
| 487 | int error; |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 488 | |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 489 | for (i = from; i < 10; i++) { |
| 490 | error = ps3_repository_read_bus_type(i, &type); |
| 491 | if (error) { |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 492 | pr_devel("%s:%d read_bus_type failed\n", |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 493 | __func__, __LINE__); |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 494 | *bus_index = UINT_MAX; |
| 495 | return error; |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 496 | } |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 497 | if (type == bus_type) { |
| 498 | *bus_index = i; |
| 499 | return 0; |
| 500 | } |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 501 | } |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 502 | *bus_index = UINT_MAX; |
| 503 | return -ENODEV; |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 504 | } |
| 505 | |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 506 | int ps3_repository_find_interrupt(const struct ps3_repository_device *repo, |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 507 | enum ps3_interrupt_type intr_type, unsigned int *interrupt_id) |
| 508 | { |
| 509 | int result = 0; |
| 510 | unsigned int res_index; |
| 511 | |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 512 | pr_devel("%s:%d: find intr_type %u\n", __func__, __LINE__, intr_type); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 513 | |
| 514 | *interrupt_id = UINT_MAX; |
| 515 | |
| 516 | for (res_index = 0; res_index < 10; res_index++) { |
| 517 | enum ps3_interrupt_type t; |
| 518 | unsigned int id; |
| 519 | |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 520 | result = ps3_repository_read_dev_intr(repo->bus_index, |
| 521 | repo->dev_index, res_index, &t, &id); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 522 | |
| 523 | if (result) { |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 524 | pr_devel("%s:%d read_dev_intr failed\n", |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 525 | __func__, __LINE__); |
| 526 | return result; |
| 527 | } |
| 528 | |
| 529 | if (t == intr_type) { |
| 530 | *interrupt_id = id; |
| 531 | break; |
| 532 | } |
| 533 | } |
| 534 | |
Geoff Levand | eebb81c | 2007-01-26 19:07:47 -0800 | [diff] [blame] | 535 | if (res_index == 10) |
| 536 | return -ENODEV; |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 537 | |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 538 | pr_devel("%s:%d: found intr_type %u at res_index %u\n", |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 539 | __func__, __LINE__, intr_type, res_index); |
| 540 | |
| 541 | return result; |
| 542 | } |
| 543 | |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 544 | int ps3_repository_find_reg(const struct ps3_repository_device *repo, |
Geoff Levand | eebb81c | 2007-01-26 19:07:47 -0800 | [diff] [blame] | 545 | enum ps3_reg_type reg_type, u64 *bus_addr, u64 *len) |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 546 | { |
| 547 | int result = 0; |
| 548 | unsigned int res_index; |
| 549 | |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 550 | pr_devel("%s:%d: find reg_type %u\n", __func__, __LINE__, reg_type); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 551 | |
| 552 | *bus_addr = *len = 0; |
| 553 | |
| 554 | for (res_index = 0; res_index < 10; res_index++) { |
Geoff Levand | eebb81c | 2007-01-26 19:07:47 -0800 | [diff] [blame] | 555 | enum ps3_reg_type t; |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 556 | u64 a; |
| 557 | u64 l; |
| 558 | |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 559 | result = ps3_repository_read_dev_reg(repo->bus_index, |
| 560 | repo->dev_index, res_index, &t, &a, &l); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 561 | |
| 562 | if (result) { |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 563 | pr_devel("%s:%d read_dev_reg failed\n", |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 564 | __func__, __LINE__); |
| 565 | return result; |
| 566 | } |
| 567 | |
| 568 | if (t == reg_type) { |
| 569 | *bus_addr = a; |
| 570 | *len = l; |
| 571 | break; |
| 572 | } |
| 573 | } |
| 574 | |
Geoff Levand | eebb81c | 2007-01-26 19:07:47 -0800 | [diff] [blame] | 575 | if (res_index == 10) |
| 576 | return -ENODEV; |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 577 | |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 578 | pr_devel("%s:%d: found reg_type %u at res_index %u\n", |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 579 | __func__, __LINE__, reg_type, res_index); |
| 580 | |
| 581 | return result; |
| 582 | } |
| 583 | |
Geert Uytterhoeven | 6c7be7d | 2007-01-26 19:07:51 -0800 | [diff] [blame] | 584 | int ps3_repository_read_stor_dev_port(unsigned int bus_index, |
| 585 | unsigned int dev_index, u64 *port) |
| 586 | { |
| 587 | return read_node(PS3_LPAR_ID_PME, |
| 588 | make_first_field("bus", bus_index), |
| 589 | make_field("dev", dev_index), |
| 590 | make_field("port", 0), |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 591 | 0, port, NULL); |
Geert Uytterhoeven | 6c7be7d | 2007-01-26 19:07:51 -0800 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | int ps3_repository_read_stor_dev_blk_size(unsigned int bus_index, |
| 595 | unsigned int dev_index, u64 *blk_size) |
| 596 | { |
| 597 | return read_node(PS3_LPAR_ID_PME, |
| 598 | make_first_field("bus", bus_index), |
| 599 | make_field("dev", dev_index), |
| 600 | make_field("blk_size", 0), |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 601 | 0, blk_size, NULL); |
Geert Uytterhoeven | 6c7be7d | 2007-01-26 19:07:51 -0800 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | int ps3_repository_read_stor_dev_num_blocks(unsigned int bus_index, |
| 605 | unsigned int dev_index, u64 *num_blocks) |
| 606 | { |
| 607 | return read_node(PS3_LPAR_ID_PME, |
| 608 | make_first_field("bus", bus_index), |
| 609 | make_field("dev", dev_index), |
| 610 | make_field("n_blocks", 0), |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 611 | 0, num_blocks, NULL); |
Geert Uytterhoeven | 6c7be7d | 2007-01-26 19:07:51 -0800 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | int ps3_repository_read_stor_dev_num_regions(unsigned int bus_index, |
| 615 | unsigned int dev_index, unsigned int *num_regions) |
| 616 | { |
| 617 | int result; |
Geoff Levand | 5233e26 | 2011-10-12 08:39:15 +0000 | [diff] [blame] | 618 | u64 v1 = 0; |
Geert Uytterhoeven | 6c7be7d | 2007-01-26 19:07:51 -0800 | [diff] [blame] | 619 | |
| 620 | result = read_node(PS3_LPAR_ID_PME, |
| 621 | make_first_field("bus", bus_index), |
| 622 | make_field("dev", dev_index), |
| 623 | make_field("n_regs", 0), |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 624 | 0, &v1, NULL); |
Geert Uytterhoeven | 6c7be7d | 2007-01-26 19:07:51 -0800 | [diff] [blame] | 625 | *num_regions = v1; |
| 626 | return result; |
| 627 | } |
| 628 | |
| 629 | int ps3_repository_read_stor_dev_region_id(unsigned int bus_index, |
| 630 | unsigned int dev_index, unsigned int region_index, |
| 631 | unsigned int *region_id) |
| 632 | { |
| 633 | int result; |
Geoff Levand | 5233e26 | 2011-10-12 08:39:15 +0000 | [diff] [blame] | 634 | u64 v1 = 0; |
Geert Uytterhoeven | 6c7be7d | 2007-01-26 19:07:51 -0800 | [diff] [blame] | 635 | |
| 636 | result = read_node(PS3_LPAR_ID_PME, |
| 637 | make_first_field("bus", bus_index), |
| 638 | make_field("dev", dev_index), |
| 639 | make_field("region", region_index), |
| 640 | make_field("id", 0), |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 641 | &v1, NULL); |
Geert Uytterhoeven | 6c7be7d | 2007-01-26 19:07:51 -0800 | [diff] [blame] | 642 | *region_id = v1; |
| 643 | return result; |
| 644 | } |
| 645 | |
| 646 | int ps3_repository_read_stor_dev_region_size(unsigned int bus_index, |
| 647 | unsigned int dev_index, unsigned int region_index, u64 *region_size) |
| 648 | { |
| 649 | return read_node(PS3_LPAR_ID_PME, |
| 650 | make_first_field("bus", bus_index), |
| 651 | make_field("dev", dev_index), |
| 652 | make_field("region", region_index), |
| 653 | make_field("size", 0), |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 654 | region_size, NULL); |
Geert Uytterhoeven | 6c7be7d | 2007-01-26 19:07:51 -0800 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | int ps3_repository_read_stor_dev_region_start(unsigned int bus_index, |
| 658 | unsigned int dev_index, unsigned int region_index, u64 *region_start) |
| 659 | { |
| 660 | return read_node(PS3_LPAR_ID_PME, |
| 661 | make_first_field("bus", bus_index), |
| 662 | make_field("dev", dev_index), |
| 663 | make_field("region", region_index), |
| 664 | make_field("start", 0), |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 665 | region_start, NULL); |
Geert Uytterhoeven | 6c7be7d | 2007-01-26 19:07:51 -0800 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | int ps3_repository_read_stor_dev_info(unsigned int bus_index, |
| 669 | unsigned int dev_index, u64 *port, u64 *blk_size, |
| 670 | u64 *num_blocks, unsigned int *num_regions) |
| 671 | { |
| 672 | int result; |
| 673 | |
| 674 | result = ps3_repository_read_stor_dev_port(bus_index, dev_index, port); |
| 675 | if (result) |
| 676 | return result; |
| 677 | |
| 678 | result = ps3_repository_read_stor_dev_blk_size(bus_index, dev_index, |
| 679 | blk_size); |
| 680 | if (result) |
| 681 | return result; |
| 682 | |
| 683 | result = ps3_repository_read_stor_dev_num_blocks(bus_index, dev_index, |
| 684 | num_blocks); |
| 685 | if (result) |
| 686 | return result; |
| 687 | |
| 688 | result = ps3_repository_read_stor_dev_num_regions(bus_index, dev_index, |
| 689 | num_regions); |
| 690 | return result; |
| 691 | } |
| 692 | |
| 693 | int ps3_repository_read_stor_dev_region(unsigned int bus_index, |
| 694 | unsigned int dev_index, unsigned int region_index, |
| 695 | unsigned int *region_id, u64 *region_start, u64 *region_size) |
| 696 | { |
| 697 | int result; |
| 698 | |
| 699 | result = ps3_repository_read_stor_dev_region_id(bus_index, dev_index, |
| 700 | region_index, region_id); |
| 701 | if (result) |
| 702 | return result; |
| 703 | |
| 704 | result = ps3_repository_read_stor_dev_region_start(bus_index, dev_index, |
| 705 | region_index, region_start); |
| 706 | if (result) |
| 707 | return result; |
| 708 | |
| 709 | result = ps3_repository_read_stor_dev_region_size(bus_index, dev_index, |
| 710 | region_index, region_size); |
| 711 | return result; |
| 712 | } |
| 713 | |
Takashi Yamamoto | c2b16e1 | 2008-01-19 07:32:31 +1100 | [diff] [blame] | 714 | /** |
| 715 | * ps3_repository_read_num_pu - Number of logical PU processors for this lpar. |
| 716 | */ |
| 717 | |
| 718 | int ps3_repository_read_num_pu(u64 *num_pu) |
| 719 | { |
| 720 | *num_pu = 0; |
| 721 | return read_node(PS3_LPAR_ID_CURRENT, |
| 722 | make_first_field("bi", 0), |
| 723 | make_field("pun", 0), |
| 724 | 0, 0, |
| 725 | num_pu, NULL); |
| 726 | } |
| 727 | |
| 728 | /** |
| 729 | * ps3_repository_read_pu_id - Read the logical PU id. |
| 730 | * @pu_index: Zero based index. |
| 731 | * @pu_id: The logical PU id. |
| 732 | */ |
| 733 | |
| 734 | int ps3_repository_read_pu_id(unsigned int pu_index, u64 *pu_id) |
| 735 | { |
| 736 | return read_node(PS3_LPAR_ID_CURRENT, |
| 737 | make_first_field("bi", 0), |
| 738 | make_field("pu", pu_index), |
| 739 | 0, 0, |
| 740 | pu_id, NULL); |
| 741 | } |
| 742 | |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 743 | int ps3_repository_read_rm_size(unsigned int ppe_id, u64 *rm_size) |
| 744 | { |
| 745 | return read_node(PS3_LPAR_ID_CURRENT, |
| 746 | make_first_field("bi", 0), |
| 747 | make_field("pu", 0), |
| 748 | ppe_id, |
| 749 | make_field("rm_size", 0), |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 750 | rm_size, NULL); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | int ps3_repository_read_region_total(u64 *region_total) |
| 754 | { |
| 755 | return read_node(PS3_LPAR_ID_CURRENT, |
| 756 | make_first_field("bi", 0), |
| 757 | make_field("rgntotal", 0), |
| 758 | 0, 0, |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 759 | region_total, NULL); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | /** |
| 763 | * ps3_repository_read_mm_info - Read mm info for single pu system. |
| 764 | * @rm_base: Real mode memory base address. |
| 765 | * @rm_size: Real mode memory size. |
| 766 | * @region_total: Maximum memory region size. |
| 767 | */ |
| 768 | |
| 769 | int ps3_repository_read_mm_info(u64 *rm_base, u64 *rm_size, u64 *region_total) |
| 770 | { |
| 771 | int result; |
| 772 | u64 ppe_id; |
| 773 | |
| 774 | lv1_get_logical_ppe_id(&ppe_id); |
| 775 | *rm_base = 0; |
| 776 | result = ps3_repository_read_rm_size(ppe_id, rm_size); |
| 777 | return result ? result |
| 778 | : ps3_repository_read_region_total(region_total); |
| 779 | } |
| 780 | |
| 781 | /** |
| 782 | * ps3_repository_read_num_spu_reserved - Number of physical spus reserved. |
| 783 | * @num_spu: Number of physical spus. |
| 784 | */ |
| 785 | |
| 786 | int ps3_repository_read_num_spu_reserved(unsigned int *num_spu_reserved) |
| 787 | { |
| 788 | int result; |
Geoff Levand | 5233e26 | 2011-10-12 08:39:15 +0000 | [diff] [blame] | 789 | u64 v1 = 0; |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 790 | |
| 791 | result = read_node(PS3_LPAR_ID_CURRENT, |
| 792 | make_first_field("bi", 0), |
| 793 | make_field("spun", 0), |
| 794 | 0, 0, |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 795 | &v1, NULL); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 796 | *num_spu_reserved = v1; |
| 797 | return result; |
| 798 | } |
| 799 | |
| 800 | /** |
| 801 | * ps3_repository_read_num_spu_resource_id - Number of spu resource reservations. |
| 802 | * @num_resource_id: Number of spu resource ids. |
| 803 | */ |
| 804 | |
| 805 | int ps3_repository_read_num_spu_resource_id(unsigned int *num_resource_id) |
| 806 | { |
| 807 | int result; |
Geoff Levand | 5233e26 | 2011-10-12 08:39:15 +0000 | [diff] [blame] | 808 | u64 v1 = 0; |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 809 | |
| 810 | result = read_node(PS3_LPAR_ID_CURRENT, |
| 811 | make_first_field("bi", 0), |
| 812 | make_field("spursvn", 0), |
| 813 | 0, 0, |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 814 | &v1, NULL); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 815 | *num_resource_id = v1; |
| 816 | return result; |
| 817 | } |
| 818 | |
| 819 | /** |
| 820 | * ps3_repository_read_spu_resource_id - spu resource reservation id value. |
| 821 | * @res_index: Resource reservation index. |
| 822 | * @resource_type: Resource reservation type. |
| 823 | * @resource_id: Resource reservation id. |
| 824 | */ |
| 825 | |
| 826 | int ps3_repository_read_spu_resource_id(unsigned int res_index, |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 827 | enum ps3_spu_resource_type *resource_type, unsigned int *resource_id) |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 828 | { |
| 829 | int result; |
Geoff Levand | 5233e26 | 2011-10-12 08:39:15 +0000 | [diff] [blame] | 830 | u64 v1 = 0; |
| 831 | u64 v2 = 0; |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 832 | |
| 833 | result = read_node(PS3_LPAR_ID_CURRENT, |
| 834 | make_first_field("bi", 0), |
| 835 | make_field("spursv", 0), |
| 836 | res_index, |
| 837 | 0, |
| 838 | &v1, &v2); |
| 839 | *resource_type = v1; |
| 840 | *resource_id = v2; |
| 841 | return result; |
| 842 | } |
| 843 | |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 844 | static int ps3_repository_read_boot_dat_address(u64 *address) |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 845 | { |
| 846 | return read_node(PS3_LPAR_ID_CURRENT, |
| 847 | make_first_field("bi", 0), |
| 848 | make_field("boot_dat", 0), |
| 849 | make_field("address", 0), |
| 850 | 0, |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 851 | address, NULL); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | int ps3_repository_read_boot_dat_size(unsigned int *size) |
| 855 | { |
| 856 | int result; |
Geoff Levand | 5233e26 | 2011-10-12 08:39:15 +0000 | [diff] [blame] | 857 | u64 v1 = 0; |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 858 | |
| 859 | result = read_node(PS3_LPAR_ID_CURRENT, |
| 860 | make_first_field("bi", 0), |
| 861 | make_field("boot_dat", 0), |
| 862 | make_field("size", 0), |
| 863 | 0, |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 864 | &v1, NULL); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 865 | *size = v1; |
| 866 | return result; |
| 867 | } |
| 868 | |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 869 | int ps3_repository_read_vuart_av_port(unsigned int *port) |
| 870 | { |
| 871 | int result; |
Geoff Levand | 5233e26 | 2011-10-12 08:39:15 +0000 | [diff] [blame] | 872 | u64 v1 = 0; |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 873 | |
| 874 | result = read_node(PS3_LPAR_ID_CURRENT, |
| 875 | make_first_field("bi", 0), |
| 876 | make_field("vir_uart", 0), |
| 877 | make_field("port", 0), |
| 878 | make_field("avset", 0), |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 879 | &v1, NULL); |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 880 | *port = v1; |
| 881 | return result; |
| 882 | } |
| 883 | |
| 884 | int ps3_repository_read_vuart_sysmgr_port(unsigned int *port) |
| 885 | { |
| 886 | int result; |
Geoff Levand | 5233e26 | 2011-10-12 08:39:15 +0000 | [diff] [blame] | 887 | u64 v1 = 0; |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 888 | |
| 889 | result = read_node(PS3_LPAR_ID_CURRENT, |
| 890 | make_first_field("bi", 0), |
| 891 | make_field("vir_uart", 0), |
| 892 | make_field("port", 0), |
| 893 | make_field("sysmgr", 0), |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 894 | &v1, NULL); |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 895 | *port = v1; |
| 896 | return result; |
| 897 | } |
| 898 | |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 899 | /** |
| 900 | * ps3_repository_read_boot_dat_info - Get address and size of cell_ext_os_area. |
| 901 | * address: lpar address of cell_ext_os_area |
| 902 | * @size: size of cell_ext_os_area |
| 903 | */ |
| 904 | |
| 905 | int ps3_repository_read_boot_dat_info(u64 *lpar_addr, unsigned int *size) |
| 906 | { |
| 907 | int result; |
| 908 | |
| 909 | *size = 0; |
| 910 | result = ps3_repository_read_boot_dat_address(lpar_addr); |
| 911 | return result ? result |
| 912 | : ps3_repository_read_boot_dat_size(size); |
| 913 | } |
| 914 | |
Takashi Yamamoto | c2b16e1 | 2008-01-19 07:32:31 +1100 | [diff] [blame] | 915 | /** |
| 916 | * ps3_repository_read_num_be - Number of physical BE processors in the system. |
| 917 | */ |
| 918 | |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 919 | int ps3_repository_read_num_be(unsigned int *num_be) |
| 920 | { |
| 921 | int result; |
Geoff Levand | 5233e26 | 2011-10-12 08:39:15 +0000 | [diff] [blame] | 922 | u64 v1 = 0; |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 923 | |
| 924 | result = read_node(PS3_LPAR_ID_PME, |
| 925 | make_first_field("ben", 0), |
| 926 | 0, |
| 927 | 0, |
| 928 | 0, |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 929 | &v1, NULL); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 930 | *num_be = v1; |
| 931 | return result; |
| 932 | } |
| 933 | |
Takashi Yamamoto | c2b16e1 | 2008-01-19 07:32:31 +1100 | [diff] [blame] | 934 | /** |
| 935 | * ps3_repository_read_be_node_id - Read the physical BE processor node id. |
| 936 | * @be_index: Zero based index. |
| 937 | * @node_id: The BE processor node id. |
| 938 | */ |
| 939 | |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 940 | int ps3_repository_read_be_node_id(unsigned int be_index, u64 *node_id) |
| 941 | { |
| 942 | return read_node(PS3_LPAR_ID_PME, |
| 943 | make_first_field("be", be_index), |
| 944 | 0, |
| 945 | 0, |
| 946 | 0, |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 947 | node_id, NULL); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 948 | } |
| 949 | |
Takashi Yamamoto | c2b16e1 | 2008-01-19 07:32:31 +1100 | [diff] [blame] | 950 | /** |
| 951 | * ps3_repository_read_be_id - Read the physical BE processor id. |
| 952 | * @node_id: The BE processor node id. |
| 953 | * @be_id: The BE processor id. |
| 954 | */ |
| 955 | |
| 956 | int ps3_repository_read_be_id(u64 node_id, u64 *be_id) |
| 957 | { |
| 958 | return read_node(PS3_LPAR_ID_PME, |
| 959 | make_first_field("be", 0), |
| 960 | node_id, |
| 961 | 0, |
| 962 | 0, |
| 963 | be_id, NULL); |
| 964 | } |
| 965 | |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 966 | int ps3_repository_read_tb_freq(u64 node_id, u64 *tb_freq) |
| 967 | { |
| 968 | return read_node(PS3_LPAR_ID_PME, |
| 969 | make_first_field("be", 0), |
| 970 | node_id, |
| 971 | make_field("clock", 0), |
| 972 | 0, |
Geert Uytterhoeven | 720c913 | 2008-01-19 07:32:24 +1100 | [diff] [blame] | 973 | tb_freq, NULL); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | int ps3_repository_read_be_tb_freq(unsigned int be_index, u64 *tb_freq) |
| 977 | { |
| 978 | int result; |
| 979 | u64 node_id; |
| 980 | |
| 981 | *tb_freq = 0; |
Takashi Yamamoto | c2b16e1 | 2008-01-19 07:32:31 +1100 | [diff] [blame] | 982 | result = ps3_repository_read_be_node_id(be_index, &node_id); |
Geoff Levand | 6e74b38 | 2006-11-23 00:46:55 +0100 | [diff] [blame] | 983 | return result ? result |
| 984 | : ps3_repository_read_tb_freq(node_id, tb_freq); |
| 985 | } |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 986 | |
Takashi Yamamoto | c2b16e1 | 2008-01-19 07:32:31 +1100 | [diff] [blame] | 987 | int ps3_repository_read_lpm_privileges(unsigned int be_index, u64 *lpar, |
| 988 | u64 *rights) |
| 989 | { |
| 990 | int result; |
| 991 | u64 node_id; |
| 992 | |
| 993 | *lpar = 0; |
| 994 | *rights = 0; |
| 995 | result = ps3_repository_read_be_node_id(be_index, &node_id); |
| 996 | return result ? result |
| 997 | : read_node(PS3_LPAR_ID_PME, |
| 998 | make_first_field("be", 0), |
| 999 | node_id, |
| 1000 | make_field("lpm", 0), |
| 1001 | make_field("priv", 0), |
| 1002 | lpar, rights); |
| 1003 | } |
| 1004 | |
Geoff Levand | 07c044c | 2012-03-31 18:03:30 -0700 | [diff] [blame^] | 1005 | #if defined(CONFIG_PS3_REPOSITORY_WRITE) |
| 1006 | |
| 1007 | static int create_node(u64 n1, u64 n2, u64 n3, u64 n4, u64 v1, u64 v2) |
| 1008 | { |
| 1009 | int result; |
| 1010 | |
| 1011 | dump_node(0, n1, n2, n3, n4, v1, v2); |
| 1012 | |
| 1013 | result = lv1_create_repository_node(n1, n2, n3, n4, v1, v2); |
| 1014 | |
| 1015 | if (result) { |
| 1016 | pr_devel("%s:%d: lv1_create_repository_node failed: %s\n", |
| 1017 | __func__, __LINE__, ps3_result(result)); |
| 1018 | return -ENOENT; |
| 1019 | } |
| 1020 | |
| 1021 | return 0; |
| 1022 | } |
| 1023 | |
| 1024 | static int delete_node(u64 n1, u64 n2, u64 n3, u64 n4) |
| 1025 | { |
| 1026 | int result; |
| 1027 | |
| 1028 | dump_node(0, n1, n2, n3, n4, 0, 0); |
| 1029 | |
| 1030 | result = lv1_delete_repository_node(n1, n2, n3, n4); |
| 1031 | |
| 1032 | if (result) { |
| 1033 | pr_devel("%s:%d: lv1_delete_repository_node failed: %s\n", |
| 1034 | __func__, __LINE__, ps3_result(result)); |
| 1035 | return -ENOENT; |
| 1036 | } |
| 1037 | |
| 1038 | return 0; |
| 1039 | } |
| 1040 | |
| 1041 | static int write_node(u64 n1, u64 n2, u64 n3, u64 n4, u64 v1, u64 v2) |
| 1042 | { |
| 1043 | int result; |
| 1044 | |
| 1045 | result = create_node(n1, n2, n3, n4, v1, v2); |
| 1046 | |
| 1047 | if (!result) |
| 1048 | return 0; |
| 1049 | |
| 1050 | result = lv1_write_repository_node(n1, n2, n3, n4, v1, v2); |
| 1051 | |
| 1052 | if (result) { |
| 1053 | pr_devel("%s:%d: lv1_write_repository_node failed: %s\n", |
| 1054 | __func__, __LINE__, ps3_result(result)); |
| 1055 | return -ENOENT; |
| 1056 | } |
| 1057 | |
| 1058 | return 0; |
| 1059 | } |
| 1060 | |
| 1061 | #endif /* defined(CONFIG_PS3_WRITE_REPOSITORY) */ |
| 1062 | |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 1063 | #if defined(DEBUG) |
| 1064 | |
| 1065 | int ps3_repository_dump_resource_info(const struct ps3_repository_device *repo) |
| 1066 | { |
| 1067 | int result = 0; |
| 1068 | unsigned int res_index; |
| 1069 | |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 1070 | pr_devel(" -> %s:%d: (%u:%u)\n", __func__, __LINE__, |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 1071 | repo->bus_index, repo->dev_index); |
| 1072 | |
| 1073 | for (res_index = 0; res_index < 10; res_index++) { |
| 1074 | enum ps3_interrupt_type intr_type; |
| 1075 | unsigned int interrupt_id; |
| 1076 | |
| 1077 | result = ps3_repository_read_dev_intr(repo->bus_index, |
| 1078 | repo->dev_index, res_index, &intr_type, &interrupt_id); |
| 1079 | |
| 1080 | if (result) { |
| 1081 | if (result != LV1_NO_ENTRY) |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 1082 | pr_devel("%s:%d ps3_repository_read_dev_intr" |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 1083 | " (%u:%u) failed\n", __func__, __LINE__, |
| 1084 | repo->bus_index, repo->dev_index); |
| 1085 | break; |
| 1086 | } |
| 1087 | |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 1088 | pr_devel("%s:%d (%u:%u) intr_type %u, interrupt_id %u\n", |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 1089 | __func__, __LINE__, repo->bus_index, repo->dev_index, |
| 1090 | intr_type, interrupt_id); |
| 1091 | } |
| 1092 | |
| 1093 | for (res_index = 0; res_index < 10; res_index++) { |
| 1094 | enum ps3_reg_type reg_type; |
| 1095 | u64 bus_addr; |
| 1096 | u64 len; |
| 1097 | |
| 1098 | result = ps3_repository_read_dev_reg(repo->bus_index, |
| 1099 | repo->dev_index, res_index, ®_type, &bus_addr, &len); |
| 1100 | |
| 1101 | if (result) { |
| 1102 | if (result != LV1_NO_ENTRY) |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 1103 | pr_devel("%s:%d ps3_repository_read_dev_reg" |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 1104 | " (%u:%u) failed\n", __func__, __LINE__, |
| 1105 | repo->bus_index, repo->dev_index); |
| 1106 | break; |
| 1107 | } |
| 1108 | |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 1109 | pr_devel("%s:%d (%u:%u) reg_type %u, bus_addr %llxh, len %llxh\n", |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 1110 | __func__, __LINE__, repo->bus_index, repo->dev_index, |
| 1111 | reg_type, bus_addr, len); |
| 1112 | } |
| 1113 | |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 1114 | pr_devel(" <- %s:%d\n", __func__, __LINE__); |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 1115 | return result; |
| 1116 | } |
| 1117 | |
| 1118 | static int dump_stor_dev_info(struct ps3_repository_device *repo) |
| 1119 | { |
| 1120 | int result = 0; |
| 1121 | unsigned int num_regions, region_index; |
| 1122 | u64 port, blk_size, num_blocks; |
| 1123 | |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 1124 | pr_devel(" -> %s:%d: (%u:%u)\n", __func__, __LINE__, |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 1125 | repo->bus_index, repo->dev_index); |
| 1126 | |
| 1127 | result = ps3_repository_read_stor_dev_info(repo->bus_index, |
| 1128 | repo->dev_index, &port, &blk_size, &num_blocks, &num_regions); |
| 1129 | if (result) { |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 1130 | pr_devel("%s:%d ps3_repository_read_stor_dev_info" |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 1131 | " (%u:%u) failed\n", __func__, __LINE__, |
| 1132 | repo->bus_index, repo->dev_index); |
| 1133 | goto out; |
| 1134 | } |
| 1135 | |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 1136 | pr_devel("%s:%d (%u:%u): port %llu, blk_size %llu, num_blocks " |
| 1137 | "%llu, num_regions %u\n", |
| 1138 | __func__, __LINE__, repo->bus_index, repo->dev_index, |
| 1139 | port, blk_size, num_blocks, num_regions); |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 1140 | |
| 1141 | for (region_index = 0; region_index < num_regions; region_index++) { |
| 1142 | unsigned int region_id; |
| 1143 | u64 region_start, region_size; |
| 1144 | |
| 1145 | result = ps3_repository_read_stor_dev_region(repo->bus_index, |
| 1146 | repo->dev_index, region_index, ®ion_id, |
| 1147 | ®ion_start, ®ion_size); |
| 1148 | if (result) { |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 1149 | pr_devel("%s:%d ps3_repository_read_stor_dev_region" |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 1150 | " (%u:%u) failed\n", __func__, __LINE__, |
| 1151 | repo->bus_index, repo->dev_index); |
| 1152 | break; |
| 1153 | } |
| 1154 | |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 1155 | pr_devel("%s:%d (%u:%u) region_id %u, start %lxh, size %lxh\n", |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 1156 | __func__, __LINE__, repo->bus_index, repo->dev_index, |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 1157 | region_id, (unsigned long)region_start, |
| 1158 | (unsigned long)region_size); |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | out: |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 1162 | pr_devel(" <- %s:%d\n", __func__, __LINE__); |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 1163 | return result; |
| 1164 | } |
| 1165 | |
| 1166 | static int dump_device_info(struct ps3_repository_device *repo, |
| 1167 | unsigned int num_dev) |
| 1168 | { |
| 1169 | int result = 0; |
| 1170 | |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 1171 | pr_devel(" -> %s:%d: bus_%u\n", __func__, __LINE__, repo->bus_index); |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 1172 | |
| 1173 | for (repo->dev_index = 0; repo->dev_index < num_dev; |
| 1174 | repo->dev_index++) { |
| 1175 | |
| 1176 | result = ps3_repository_read_dev_type(repo->bus_index, |
| 1177 | repo->dev_index, &repo->dev_type); |
| 1178 | |
| 1179 | if (result) { |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 1180 | pr_devel("%s:%d ps3_repository_read_dev_type" |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 1181 | " (%u:%u) failed\n", __func__, __LINE__, |
| 1182 | repo->bus_index, repo->dev_index); |
| 1183 | break; |
| 1184 | } |
| 1185 | |
| 1186 | result = ps3_repository_read_dev_id(repo->bus_index, |
| 1187 | repo->dev_index, &repo->dev_id); |
| 1188 | |
| 1189 | if (result) { |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 1190 | pr_devel("%s:%d ps3_repository_read_dev_id" |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 1191 | " (%u:%u) failed\n", __func__, __LINE__, |
| 1192 | repo->bus_index, repo->dev_index); |
| 1193 | continue; |
| 1194 | } |
| 1195 | |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 1196 | pr_devel("%s:%d (%u:%u): dev_type %u, dev_id %lu\n", __func__, |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 1197 | __LINE__, repo->bus_index, repo->dev_index, |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 1198 | repo->dev_type, (unsigned long)repo->dev_id); |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 1199 | |
| 1200 | ps3_repository_dump_resource_info(repo); |
| 1201 | |
| 1202 | if (repo->bus_type == PS3_BUS_TYPE_STORAGE) |
| 1203 | dump_stor_dev_info(repo); |
| 1204 | } |
| 1205 | |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 1206 | pr_devel(" <- %s:%d\n", __func__, __LINE__); |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 1207 | return result; |
| 1208 | } |
| 1209 | |
| 1210 | int ps3_repository_dump_bus_info(void) |
| 1211 | { |
| 1212 | int result = 0; |
| 1213 | struct ps3_repository_device repo; |
| 1214 | |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 1215 | pr_devel(" -> %s:%d\n", __func__, __LINE__); |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 1216 | |
| 1217 | memset(&repo, 0, sizeof(repo)); |
| 1218 | |
| 1219 | for (repo.bus_index = 0; repo.bus_index < 10; repo.bus_index++) { |
| 1220 | unsigned int num_dev; |
| 1221 | |
| 1222 | result = ps3_repository_read_bus_type(repo.bus_index, |
| 1223 | &repo.bus_type); |
| 1224 | |
| 1225 | if (result) { |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 1226 | pr_devel("%s:%d read_bus_type(%u) failed\n", |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 1227 | __func__, __LINE__, repo.bus_index); |
| 1228 | break; |
| 1229 | } |
| 1230 | |
| 1231 | result = ps3_repository_read_bus_id(repo.bus_index, |
| 1232 | &repo.bus_id); |
| 1233 | |
| 1234 | if (result) { |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 1235 | pr_devel("%s:%d read_bus_id(%u) failed\n", |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 1236 | __func__, __LINE__, repo.bus_index); |
| 1237 | continue; |
| 1238 | } |
| 1239 | |
| 1240 | if (repo.bus_index != repo.bus_id) |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 1241 | pr_devel("%s:%d bus_index != bus_id\n", |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 1242 | __func__, __LINE__); |
| 1243 | |
| 1244 | result = ps3_repository_read_bus_num_dev(repo.bus_index, |
| 1245 | &num_dev); |
| 1246 | |
| 1247 | if (result) { |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 1248 | pr_devel("%s:%d read_bus_num_dev(%u) failed\n", |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 1249 | __func__, __LINE__, repo.bus_index); |
| 1250 | continue; |
| 1251 | } |
| 1252 | |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 1253 | pr_devel("%s:%d bus_%u: bus_type %u, bus_id %lu, num_dev %u\n", |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 1254 | __func__, __LINE__, repo.bus_index, repo.bus_type, |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 1255 | (unsigned long)repo.bus_id, num_dev); |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 1256 | |
| 1257 | dump_device_info(&repo, num_dev); |
| 1258 | } |
| 1259 | |
Geoff Levand | 4bf94ae | 2011-12-01 08:58:58 +0000 | [diff] [blame] | 1260 | pr_devel(" <- %s:%d\n", __func__, __LINE__); |
Geoff Levand | a3323d1 | 2007-06-16 07:55:58 +1000 | [diff] [blame] | 1261 | return result; |
| 1262 | } |
| 1263 | |
| 1264 | #endif /* defined(DEBUG) */ |