Andrew F. Davis | a513b2a | 2018-05-04 19:06:09 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Texas Instruments System Control Interface Driver |
| 3 | * Based on Linux and U-Boot implementation |
| 4 | * |
| 5 | * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/ |
| 6 | * |
| 7 | * SPDX-License-Identifier: BSD-3-Clause |
| 8 | */ |
| 9 | |
| 10 | #include <debug.h> |
| 11 | #include <errno.h> |
| 12 | #include <platform_def.h> |
| 13 | #include <stdbool.h> |
| 14 | #include <stddef.h> |
| 15 | #include <string.h> |
| 16 | |
| 17 | #include <sec_proxy.h> |
| 18 | |
| 19 | #include "ti_sci_protocol.h" |
| 20 | #include "ti_sci.h" |
| 21 | |
| 22 | /** |
| 23 | * struct ti_sci_desc - Description of SoC integration |
| 24 | * @host_id: Host identifier representing the compute entity |
| 25 | * @max_msg_size: Maximum size of data per message that can be handled |
| 26 | */ |
| 27 | struct ti_sci_desc { |
| 28 | uint8_t host_id; |
| 29 | int max_msg_size; |
| 30 | }; |
| 31 | |
| 32 | /** |
| 33 | * struct ti_sci_info - Structure representing a TI SCI instance |
| 34 | * @desc: SoC description for this instance |
| 35 | * @seq: Seq id used for verification for tx and rx message |
| 36 | */ |
| 37 | struct ti_sci_info { |
| 38 | const struct ti_sci_desc desc; |
| 39 | uint8_t seq; |
| 40 | }; |
| 41 | |
| 42 | static struct ti_sci_info info = { |
| 43 | .desc = { |
| 44 | .host_id = TI_SCI_HOST_ID, |
| 45 | .max_msg_size = TI_SCI_MAX_MESSAGE_SIZE, |
| 46 | }, |
| 47 | .seq = 0x0a, |
| 48 | }; |
| 49 | |
| 50 | /** |
| 51 | * struct ti_sci_xfer - Structure representing a message flow |
| 52 | * @tx_message: Transmit message |
| 53 | * @rx_message: Receive message |
| 54 | */ |
| 55 | struct ti_sci_xfer { |
| 56 | struct k3_sec_proxy_msg tx_message; |
| 57 | struct k3_sec_proxy_msg rx_message; |
| 58 | }; |
| 59 | |
| 60 | /** |
| 61 | * ti_sci_setup_one_xfer() - Setup one message type |
| 62 | * |
| 63 | * @msg_type: Message type |
| 64 | * @msg_flags: Flag to set for the message |
| 65 | * @tx_buf: Buffer to be sent to mailbox channel |
| 66 | * @tx_message_size: transmit message size |
| 67 | * @rx_buf: Buffer to be received from mailbox channel |
| 68 | * @rx_message_size: receive message size |
| 69 | * |
| 70 | * Helper function which is used by various command functions that are |
| 71 | * exposed to clients of this driver for allocating a message traffic event. |
| 72 | * |
| 73 | * Return: 0 if all goes well, else appropriate error message |
| 74 | */ |
| 75 | static int ti_sci_setup_one_xfer(uint16_t msg_type, uint32_t msg_flags, |
| 76 | void *tx_buf, |
| 77 | size_t tx_message_size, |
| 78 | void *rx_buf, |
| 79 | size_t rx_message_size, |
| 80 | struct ti_sci_xfer *xfer) |
| 81 | { |
| 82 | struct ti_sci_msg_hdr *hdr; |
| 83 | |
| 84 | /* Ensure we have sane transfer sizes */ |
| 85 | if (rx_message_size > info.desc.max_msg_size || |
| 86 | tx_message_size > info.desc.max_msg_size || |
| 87 | rx_message_size < sizeof(*hdr) || |
| 88 | tx_message_size < sizeof(*hdr)) |
| 89 | return -ERANGE; |
| 90 | |
| 91 | info.seq++; |
| 92 | |
| 93 | hdr = (struct ti_sci_msg_hdr *)tx_buf; |
| 94 | hdr->seq = info.seq; |
| 95 | hdr->type = msg_type; |
| 96 | hdr->host = info.desc.host_id; |
| 97 | hdr->flags = msg_flags; |
| 98 | |
| 99 | xfer->tx_message.buf = tx_buf; |
| 100 | xfer->tx_message.len = tx_message_size; |
| 101 | |
| 102 | xfer->rx_message.buf = rx_buf; |
| 103 | xfer->rx_message.len = rx_message_size; |
| 104 | |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * ti_sci_get_response() - Receive response from mailbox channel |
| 110 | * |
| 111 | * @xfer: Transfer to initiate and wait for response |
| 112 | * @chan: Channel to receive the response |
| 113 | * |
| 114 | * Return: 0 if all goes well, else appropriate error message |
| 115 | */ |
| 116 | static inline int ti_sci_get_response(struct ti_sci_xfer *xfer, |
| 117 | enum k3_sec_proxy_chan_id chan) |
| 118 | { |
| 119 | struct k3_sec_proxy_msg *msg = &xfer->rx_message; |
| 120 | struct ti_sci_msg_hdr *hdr; |
| 121 | int ret; |
| 122 | |
| 123 | /* Receive the response */ |
| 124 | ret = k3_sec_proxy_recv(chan, msg); |
| 125 | if (ret) { |
| 126 | ERROR("Message receive failed (%d)\n", ret); |
| 127 | return ret; |
| 128 | } |
| 129 | |
| 130 | /* msg is updated by Secure Proxy driver */ |
| 131 | hdr = (struct ti_sci_msg_hdr *)msg->buf; |
| 132 | |
| 133 | /* Sanity check for message response */ |
| 134 | if (hdr->seq != info.seq) { |
| 135 | ERROR("Message for %d is not expected\n", hdr->seq); |
| 136 | return -EINVAL; |
| 137 | } |
| 138 | |
| 139 | if (msg->len > info.desc.max_msg_size) { |
| 140 | ERROR("Unable to handle %lu xfer (max %d)\n", |
| 141 | msg->len, info.desc.max_msg_size); |
| 142 | return -EINVAL; |
| 143 | } |
| 144 | |
| 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * ti_sci_do_xfer() - Do one transfer |
| 150 | * |
| 151 | * @xfer: Transfer to initiate and wait for response |
| 152 | * |
| 153 | * Return: 0 if all goes well, else appropriate error message |
| 154 | */ |
| 155 | static inline int ti_sci_do_xfer(struct ti_sci_xfer *xfer) |
| 156 | { |
| 157 | struct k3_sec_proxy_msg *msg = &xfer->tx_message; |
| 158 | int ret; |
| 159 | |
| 160 | /* Send the message */ |
| 161 | ret = k3_sec_proxy_send(SP_HIGH_PRIORITY, msg); |
| 162 | if (ret) { |
| 163 | ERROR("Message sending failed (%d)\n", ret); |
| 164 | return ret; |
| 165 | } |
| 166 | |
| 167 | ret = ti_sci_get_response(xfer, SP_RESPONSE); |
| 168 | if (ret) { |
| 169 | ERROR("Failed to get response (%d)\n", ret); |
| 170 | return ret; |
| 171 | } |
| 172 | |
| 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * ti_sci_get_revision() - Get the revision of the SCI entity |
| 178 | * |
| 179 | * Updates the SCI information in the internal data structure. |
| 180 | * |
| 181 | * Return: 0 if all goes well, else appropriate error message |
| 182 | */ |
| 183 | int ti_sci_get_revision(struct ti_sci_msg_resp_version *rev_info) |
| 184 | { |
| 185 | struct ti_sci_msg_hdr hdr; |
| 186 | struct ti_sci_xfer xfer; |
| 187 | int ret; |
| 188 | |
| 189 | ret = ti_sci_setup_one_xfer(TI_SCI_MSG_VERSION, 0x0, |
| 190 | &hdr, sizeof(hdr), |
| 191 | rev_info, sizeof(*rev_info), |
| 192 | &xfer); |
| 193 | if (ret) { |
| 194 | ERROR("Message alloc failed (%d)\n", ret); |
| 195 | return ret; |
| 196 | } |
| 197 | |
| 198 | ret = ti_sci_do_xfer(&xfer); |
| 199 | if (ret) { |
| 200 | ERROR("Transfer send failed (%d)\n", ret); |
| 201 | return ret; |
| 202 | } |
| 203 | |
| 204 | return 0; |
| 205 | } |
| 206 | |
| 207 | /** |
Andrew F. Davis | 4f2a055 | 2018-05-04 19:06:10 +0000 | [diff] [blame] | 208 | * ti_sci_is_response_ack() - Generic ACK/NACK message check |
| 209 | * |
| 210 | * @r: pointer to response buffer |
| 211 | * |
| 212 | * Return: true if the response was an ACK, else returns false |
| 213 | */ |
| 214 | static inline bool ti_sci_is_response_ack(void *r) |
| 215 | { |
| 216 | struct ti_sci_msg_hdr *hdr = r; |
| 217 | |
| 218 | return hdr->flags & TI_SCI_FLAG_RESP_GENERIC_ACK ? true : false; |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * ti_sci_device_set_state() - Set device state |
| 223 | * |
| 224 | * @id: Device identifier |
| 225 | * @flags: flags to setup for the device |
| 226 | * @state: State to move the device to |
| 227 | * |
| 228 | * Return: 0 if all goes well, else appropriate error message |
| 229 | */ |
| 230 | int ti_sci_device_set_state(uint32_t id, uint32_t flags, uint8_t state) |
| 231 | { |
| 232 | struct ti_sci_msg_req_set_device_state req; |
| 233 | struct ti_sci_msg_hdr resp; |
| 234 | |
| 235 | struct ti_sci_xfer xfer; |
| 236 | int ret; |
| 237 | |
| 238 | ret = ti_sci_setup_one_xfer(TI_SCI_MSG_SET_DEVICE_STATE, |
| 239 | flags | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 240 | &req, sizeof(req), |
| 241 | &resp, sizeof(resp), |
| 242 | &xfer); |
| 243 | if (ret) { |
| 244 | ERROR("Message alloc failed (%d)\n", ret); |
| 245 | return ret; |
| 246 | } |
| 247 | |
| 248 | req.id = id; |
| 249 | req.state = state; |
| 250 | |
| 251 | ret = ti_sci_do_xfer(&xfer); |
| 252 | if (ret) { |
| 253 | ERROR("Transfer send failed (%d)\n", ret); |
| 254 | return ret; |
| 255 | } |
| 256 | |
| 257 | if (!ti_sci_is_response_ack(&resp)) |
| 258 | return -ENODEV; |
| 259 | |
| 260 | return 0; |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * ti_sci_device_get_state() - Get device state |
| 265 | * |
| 266 | * @id: Device Identifier |
| 267 | * @clcnt: Pointer to Context Loss Count |
| 268 | * @resets: pointer to resets |
| 269 | * @p_state: pointer to p_state |
| 270 | * @c_state: pointer to c_state |
| 271 | * |
| 272 | * Return: 0 if all goes well, else appropriate error message |
| 273 | */ |
| 274 | int ti_sci_device_get_state(uint32_t id, uint32_t *clcnt, uint32_t *resets, |
| 275 | uint8_t *p_state, uint8_t *c_state) |
| 276 | { |
| 277 | struct ti_sci_msg_req_get_device_state req; |
| 278 | struct ti_sci_msg_resp_get_device_state resp; |
| 279 | |
| 280 | struct ti_sci_xfer xfer; |
| 281 | int ret; |
| 282 | |
| 283 | if (!clcnt && !resets && !p_state && !c_state) |
| 284 | return -EINVAL; |
| 285 | |
| 286 | ret = ti_sci_setup_one_xfer(TI_SCI_MSG_GET_DEVICE_STATE, 0, |
| 287 | &req, sizeof(req), |
| 288 | &resp, sizeof(resp), |
| 289 | &xfer); |
| 290 | if (ret) { |
| 291 | ERROR("Message alloc failed (%d)\n", ret); |
| 292 | return ret; |
| 293 | } |
| 294 | |
| 295 | req.id = id; |
| 296 | |
| 297 | ret = ti_sci_do_xfer(&xfer); |
| 298 | if (ret) { |
| 299 | ERROR("Transfer send failed (%d)\n", ret); |
| 300 | return ret; |
| 301 | } |
| 302 | |
| 303 | if (!ti_sci_is_response_ack(&resp)) |
| 304 | return -ENODEV; |
| 305 | |
| 306 | if (clcnt) |
| 307 | *clcnt = resp.context_loss_count; |
| 308 | if (resets) |
| 309 | *resets = resp.resets; |
| 310 | if (p_state) |
| 311 | *p_state = resp.programmed_state; |
| 312 | if (c_state) |
| 313 | *c_state = resp.current_state; |
| 314 | |
| 315 | return 0; |
| 316 | } |
| 317 | |
| 318 | /** |
| 319 | * ti_sci_device_get() - Request for device managed by TISCI |
| 320 | * |
| 321 | * @id: Device Identifier |
| 322 | * |
| 323 | * Request for the device - NOTE: the client MUST maintain integrity of |
| 324 | * usage count by balancing get_device with put_device. No refcounting is |
| 325 | * managed by driver for that purpose. |
| 326 | * |
| 327 | * NOTE: The request is for exclusive access for the processor. |
| 328 | * |
| 329 | * Return: 0 if all goes well, else appropriate error message |
| 330 | */ |
| 331 | int ti_sci_device_get(uint32_t id) |
| 332 | { |
| 333 | return ti_sci_device_set_state(id, |
| 334 | MSG_FLAG_DEVICE_EXCLUSIVE, |
| 335 | MSG_DEVICE_SW_STATE_ON); |
| 336 | } |
| 337 | |
| 338 | /** |
| 339 | * ti_sci_device_idle() - Idle a device managed by TISCI |
| 340 | * |
| 341 | * @id: Device Identifier |
| 342 | * |
| 343 | * Request for the device - NOTE: the client MUST maintain integrity of |
| 344 | * usage count by balancing get_device with put_device. No refcounting is |
| 345 | * managed by driver for that purpose. |
| 346 | * |
| 347 | * Return: 0 if all goes well, else appropriate error message |
| 348 | */ |
| 349 | int ti_sci_device_idle(uint32_t id) |
| 350 | { |
| 351 | return ti_sci_device_set_state(id, |
| 352 | MSG_FLAG_DEVICE_EXCLUSIVE, |
| 353 | MSG_DEVICE_SW_STATE_RETENTION); |
| 354 | } |
| 355 | |
| 356 | /** |
| 357 | * ti_sci_device_put() - Release a device managed by TISCI |
| 358 | * |
| 359 | * @id: Device Identifier |
| 360 | * |
| 361 | * Request for the device - NOTE: the client MUST maintain integrity of |
| 362 | * usage count by balancing get_device with put_device. No refcounting is |
| 363 | * managed by driver for that purpose. |
| 364 | * |
| 365 | * Return: 0 if all goes well, else appropriate error message |
| 366 | */ |
| 367 | int ti_sci_device_put(uint32_t id) |
| 368 | { |
| 369 | return ti_sci_device_set_state(id, 0, MSG_DEVICE_SW_STATE_AUTO_OFF); |
| 370 | } |
| 371 | |
| 372 | /** |
| 373 | * ti_sci_device_is_valid() - Is the device valid |
| 374 | * |
| 375 | * @id: Device Identifier |
| 376 | * |
| 377 | * Return: 0 if all goes well and the device ID is valid, else return |
| 378 | * appropriate error |
| 379 | */ |
| 380 | int ti_sci_device_is_valid(uint32_t id) |
| 381 | { |
| 382 | uint8_t unused; |
| 383 | |
| 384 | /* check the device state which will also tell us if the ID is valid */ |
| 385 | return ti_sci_device_get_state(id, NULL, NULL, NULL, &unused); |
| 386 | } |
| 387 | |
| 388 | /** |
| 389 | * ti_sci_device_get_clcnt() - Get context loss counter |
| 390 | * |
| 391 | * @id: Device Identifier |
| 392 | * @count: Pointer to Context Loss counter to populate |
| 393 | * |
| 394 | * Return: 0 if all goes well, else appropriate error message |
| 395 | */ |
| 396 | int ti_sci_device_get_clcnt(uint32_t id, uint32_t *count) |
| 397 | { |
| 398 | return ti_sci_device_get_state(id, count, NULL, NULL, NULL); |
| 399 | } |
| 400 | |
| 401 | /** |
| 402 | * ti_sci_device_is_idle() - Check if the device is requested to be idle |
| 403 | * |
| 404 | * @id: Device Identifier |
| 405 | * @r_state: true if requested to be idle |
| 406 | * |
| 407 | * Return: 0 if all goes well, else appropriate error message |
| 408 | */ |
| 409 | int ti_sci_device_is_idle(uint32_t id, bool *r_state) |
| 410 | { |
| 411 | int ret; |
| 412 | uint8_t state; |
| 413 | |
| 414 | if (!r_state) |
| 415 | return -EINVAL; |
| 416 | |
| 417 | ret = ti_sci_device_get_state(id, NULL, NULL, &state, NULL); |
| 418 | if (ret) |
| 419 | return ret; |
| 420 | |
| 421 | *r_state = (state == MSG_DEVICE_SW_STATE_RETENTION); |
| 422 | |
| 423 | return 0; |
| 424 | } |
| 425 | |
| 426 | /** |
| 427 | * ti_sci_device_is_stop() - Check if the device is requested to be stopped |
| 428 | * |
| 429 | * @id: Device Identifier |
| 430 | * @r_state: true if requested to be stopped |
| 431 | * @curr_state: true if currently stopped |
| 432 | * |
| 433 | * Return: 0 if all goes well, else appropriate error message |
| 434 | */ |
| 435 | int ti_sci_device_is_stop(uint32_t id, bool *r_state, bool *curr_state) |
| 436 | { |
| 437 | int ret; |
| 438 | uint8_t p_state, c_state; |
| 439 | |
| 440 | if (!r_state && !curr_state) |
| 441 | return -EINVAL; |
| 442 | |
| 443 | ret = ti_sci_device_get_state(id, NULL, NULL, &p_state, &c_state); |
| 444 | if (ret) |
| 445 | return ret; |
| 446 | |
| 447 | if (r_state) |
| 448 | *r_state = (p_state == MSG_DEVICE_SW_STATE_AUTO_OFF); |
| 449 | if (curr_state) |
| 450 | *curr_state = (c_state == MSG_DEVICE_HW_STATE_OFF); |
| 451 | |
| 452 | return 0; |
| 453 | } |
| 454 | |
| 455 | /** |
| 456 | * ti_sci_device_is_on() - Check if the device is requested to be ON |
| 457 | * |
| 458 | * @id: Device Identifier |
| 459 | * @r_state: true if requested to be ON |
| 460 | * @curr_state: true if currently ON and active |
| 461 | * |
| 462 | * Return: 0 if all goes well, else appropriate error message |
| 463 | */ |
| 464 | int ti_sci_device_is_on(uint32_t id, bool *r_state, bool *curr_state) |
| 465 | { |
| 466 | int ret; |
| 467 | uint8_t p_state, c_state; |
| 468 | |
| 469 | if (!r_state && !curr_state) |
| 470 | return -EINVAL; |
| 471 | |
| 472 | ret = |
| 473 | ti_sci_device_get_state(id, NULL, NULL, &p_state, &c_state); |
| 474 | if (ret) |
| 475 | return ret; |
| 476 | |
| 477 | if (r_state) |
| 478 | *r_state = (p_state == MSG_DEVICE_SW_STATE_ON); |
| 479 | if (curr_state) |
| 480 | *curr_state = (c_state == MSG_DEVICE_HW_STATE_ON); |
| 481 | |
| 482 | return 0; |
| 483 | } |
| 484 | |
| 485 | /** |
| 486 | * ti_sci_device_is_trans() - Check if the device is currently transitioning |
| 487 | * |
| 488 | * @id: Device Identifier |
| 489 | * @curr_state: true if currently transitioning |
| 490 | * |
| 491 | * Return: 0 if all goes well, else appropriate error message |
| 492 | */ |
| 493 | int ti_sci_device_is_trans(uint32_t id, bool *curr_state) |
| 494 | { |
| 495 | int ret; |
| 496 | uint8_t state; |
| 497 | |
| 498 | if (!curr_state) |
| 499 | return -EINVAL; |
| 500 | |
| 501 | ret = ti_sci_device_get_state(id, NULL, NULL, NULL, &state); |
| 502 | if (ret) |
| 503 | return ret; |
| 504 | |
| 505 | *curr_state = (state == MSG_DEVICE_HW_STATE_TRANS); |
| 506 | |
| 507 | return 0; |
| 508 | } |
| 509 | |
| 510 | /** |
| 511 | * ti_sci_device_set_resets() - Set resets for device managed by TISCI |
| 512 | * |
| 513 | * @id: Device Identifier |
| 514 | * @reset_state: Device specific reset bit field |
| 515 | * |
| 516 | * Return: 0 if all goes well, else appropriate error message |
| 517 | */ |
| 518 | int ti_sci_device_set_resets(uint32_t id, uint32_t reset_state) |
| 519 | { |
| 520 | struct ti_sci_msg_req_set_device_resets req; |
| 521 | struct ti_sci_msg_hdr resp; |
| 522 | |
| 523 | struct ti_sci_xfer xfer; |
| 524 | int ret; |
| 525 | |
| 526 | ret = ti_sci_setup_one_xfer(TI_SCI_MSG_SET_DEVICE_RESETS, |
| 527 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 528 | &req, sizeof(req), |
| 529 | &resp, sizeof(resp), |
| 530 | &xfer); |
| 531 | if (ret) { |
| 532 | ERROR("Message alloc failed (%d)\n", ret); |
| 533 | return ret; |
| 534 | } |
| 535 | |
| 536 | req.id = id; |
| 537 | req.resets = reset_state; |
| 538 | |
| 539 | ret = ti_sci_do_xfer(&xfer); |
| 540 | if (ret) { |
| 541 | ERROR("Transfer send failed (%d)\n", ret); |
| 542 | return ret; |
| 543 | } |
| 544 | |
| 545 | if (!ti_sci_is_response_ack(&resp)) |
| 546 | return -ENODEV; |
| 547 | |
| 548 | return 0; |
| 549 | } |
| 550 | |
| 551 | /** |
| 552 | * ti_sci_device_get_resets() - Get reset state for device managed by TISCI |
| 553 | * |
| 554 | * @id: Device Identifier |
| 555 | * @reset_state: Pointer to reset state to populate |
| 556 | * |
| 557 | * Return: 0 if all goes well, else appropriate error message |
| 558 | */ |
| 559 | int ti_sci_device_get_resets(uint32_t id, uint32_t *reset_state) |
| 560 | { |
| 561 | return ti_sci_device_get_state(id, NULL, reset_state, NULL, NULL); |
| 562 | } |
| 563 | |
| 564 | /** |
Andrew F. Davis | dc08adf | 2018-05-04 19:06:11 +0000 | [diff] [blame] | 565 | * ti_sci_clock_set_state() - Set clock state helper |
| 566 | * |
| 567 | * @dev_id: Device identifier this request is for |
| 568 | * @clk_id: Clock identifier for the device for this request, |
| 569 | * Each device has its own set of clock inputs, This indexes |
| 570 | * which clock input to modify |
| 571 | * @flags: Header flags as needed |
| 572 | * @state: State to request for the clock |
| 573 | * |
| 574 | * Return: 0 if all goes well, else appropriate error message |
| 575 | */ |
| 576 | int ti_sci_clock_set_state(uint32_t dev_id, uint8_t clk_id, |
| 577 | uint32_t flags, uint8_t state) |
| 578 | { |
| 579 | struct ti_sci_msg_req_set_clock_state req; |
| 580 | struct ti_sci_msg_hdr resp; |
| 581 | |
| 582 | struct ti_sci_xfer xfer; |
| 583 | int ret; |
| 584 | |
| 585 | ret = ti_sci_setup_one_xfer(TI_SCI_MSG_SET_CLOCK_STATE, |
| 586 | flags | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 587 | &req, sizeof(req), |
| 588 | &resp, sizeof(resp), |
| 589 | &xfer); |
| 590 | if (ret) { |
| 591 | ERROR("Message alloc failed (%d)\n", ret); |
| 592 | return ret; |
| 593 | } |
| 594 | |
| 595 | req.dev_id = dev_id; |
| 596 | req.clk_id = clk_id; |
| 597 | req.request_state = state; |
| 598 | |
| 599 | ret = ti_sci_do_xfer(&xfer); |
| 600 | if (ret) { |
| 601 | ERROR("Transfer send failed (%d)\n", ret); |
| 602 | return ret; |
| 603 | } |
| 604 | |
| 605 | if (!ti_sci_is_response_ack(&resp)) |
| 606 | return -ENODEV; |
| 607 | |
| 608 | return 0; |
| 609 | } |
| 610 | |
| 611 | /** |
| 612 | * ti_sci_clock_get_state() - Get clock state helper |
| 613 | * |
| 614 | * @dev_id: Device identifier this request is for |
| 615 | * @clk_id: Clock identifier for the device for this request. |
| 616 | * Each device has its own set of clock inputs. This indexes |
| 617 | * which clock input to modify. |
| 618 | * @programmed_state: State requested for clock to move to |
| 619 | * @current_state: State that the clock is currently in |
| 620 | * |
| 621 | * Return: 0 if all goes well, else appropriate error message |
| 622 | */ |
| 623 | int ti_sci_clock_get_state(uint32_t dev_id, uint8_t clk_id, |
| 624 | uint8_t *programmed_state, |
| 625 | uint8_t *current_state) |
| 626 | { |
| 627 | struct ti_sci_msg_req_get_clock_state req; |
| 628 | struct ti_sci_msg_resp_get_clock_state resp; |
| 629 | |
| 630 | struct ti_sci_xfer xfer; |
| 631 | int ret; |
| 632 | |
| 633 | if (!programmed_state && !current_state) |
| 634 | return -EINVAL; |
| 635 | |
| 636 | ret = ti_sci_setup_one_xfer(TI_SCI_MSG_GET_CLOCK_STATE, |
| 637 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 638 | &req, sizeof(req), |
| 639 | &resp, sizeof(resp), |
| 640 | &xfer); |
| 641 | if (ret) { |
| 642 | ERROR("Message alloc failed (%d)\n", ret); |
| 643 | return ret; |
| 644 | } |
| 645 | |
| 646 | req.dev_id = dev_id; |
| 647 | req.clk_id = clk_id; |
| 648 | |
| 649 | ret = ti_sci_do_xfer(&xfer); |
| 650 | if (ret) { |
| 651 | ERROR("Transfer send failed (%d)\n", ret); |
| 652 | return ret; |
| 653 | } |
| 654 | |
| 655 | if (!ti_sci_is_response_ack(&resp)) |
| 656 | return -ENODEV; |
| 657 | |
| 658 | if (programmed_state) |
| 659 | *programmed_state = resp.programmed_state; |
| 660 | if (current_state) |
| 661 | *current_state = resp.current_state; |
| 662 | |
| 663 | return 0; |
| 664 | } |
| 665 | |
| 666 | /** |
| 667 | * ti_sci_clock_get() - Get control of a clock from TI SCI |
| 668 | |
| 669 | * @dev_id: Device identifier this request is for |
| 670 | * @clk_id: Clock identifier for the device for this request. |
| 671 | * Each device has its own set of clock inputs. This indexes |
| 672 | * which clock input to modify. |
| 673 | * @needs_ssc: 'true' iff Spread Spectrum clock is desired |
| 674 | * @can_change_freq: 'true' iff frequency change is desired |
| 675 | * @enable_input_term: 'true' iff input termination is desired |
| 676 | * |
| 677 | * Return: 0 if all goes well, else appropriate error message |
| 678 | */ |
| 679 | int ti_sci_clock_get(uint32_t dev_id, uint8_t clk_id, |
| 680 | bool needs_ssc, bool can_change_freq, |
| 681 | bool enable_input_term) |
| 682 | { |
| 683 | uint32_t flags = 0; |
| 684 | |
| 685 | flags |= needs_ssc ? MSG_FLAG_CLOCK_ALLOW_SSC : 0; |
| 686 | flags |= can_change_freq ? MSG_FLAG_CLOCK_ALLOW_FREQ_CHANGE : 0; |
| 687 | flags |= enable_input_term ? MSG_FLAG_CLOCK_INPUT_TERM : 0; |
| 688 | |
| 689 | return ti_sci_clock_set_state(dev_id, clk_id, flags, |
| 690 | MSG_CLOCK_SW_STATE_REQ); |
| 691 | } |
| 692 | |
| 693 | /** |
| 694 | * ti_sci_clock_idle() - Idle a clock which is in our control |
| 695 | |
| 696 | * @dev_id: Device identifier this request is for |
| 697 | * @clk_id: Clock identifier for the device for this request. |
| 698 | * Each device has its own set of clock inputs. This indexes |
| 699 | * which clock input to modify. |
| 700 | * |
| 701 | * NOTE: This clock must have been requested by get_clock previously. |
| 702 | * |
| 703 | * Return: 0 if all goes well, else appropriate error message |
| 704 | */ |
| 705 | int ti_sci_clock_idle(uint32_t dev_id, uint8_t clk_id) |
| 706 | { |
| 707 | return ti_sci_clock_set_state(dev_id, clk_id, 0, |
| 708 | MSG_CLOCK_SW_STATE_UNREQ); |
| 709 | } |
| 710 | |
| 711 | /** |
| 712 | * ti_sci_clock_put() - Release a clock from our control |
| 713 | * |
| 714 | * @dev_id: Device identifier this request is for |
| 715 | * @clk_id: Clock identifier for the device for this request. |
| 716 | * Each device has its own set of clock inputs. This indexes |
| 717 | * which clock input to modify. |
| 718 | * |
| 719 | * NOTE: This clock must have been requested by get_clock previously. |
| 720 | * |
| 721 | * Return: 0 if all goes well, else appropriate error message |
| 722 | */ |
| 723 | int ti_sci_clock_put(uint32_t dev_id, uint8_t clk_id) |
| 724 | { |
| 725 | return ti_sci_clock_set_state(dev_id, clk_id, 0, |
| 726 | MSG_CLOCK_SW_STATE_AUTO); |
| 727 | } |
| 728 | |
| 729 | /** |
| 730 | * ti_sci_clock_is_auto() - Is the clock being auto managed |
| 731 | * |
| 732 | * @dev_id: Device identifier this request is for |
| 733 | * @clk_id: Clock identifier for the device for this request. |
| 734 | * Each device has its own set of clock inputs. This indexes |
| 735 | * which clock input to modify. |
| 736 | * @req_state: state indicating if the clock is auto managed |
| 737 | * |
| 738 | * Return: 0 if all goes well, else appropriate error message |
| 739 | */ |
| 740 | int ti_sci_clock_is_auto(uint32_t dev_id, uint8_t clk_id, bool *req_state) |
| 741 | { |
| 742 | uint8_t state = 0; |
| 743 | int ret; |
| 744 | |
| 745 | if (!req_state) |
| 746 | return -EINVAL; |
| 747 | |
| 748 | ret = ti_sci_clock_get_state(dev_id, clk_id, &state, NULL); |
| 749 | if (ret) |
| 750 | return ret; |
| 751 | |
| 752 | *req_state = (state == MSG_CLOCK_SW_STATE_AUTO); |
| 753 | |
| 754 | return 0; |
| 755 | } |
| 756 | |
| 757 | /** |
| 758 | * ti_sci_clock_is_on() - Is the clock ON |
| 759 | * |
| 760 | * @dev_id: Device identifier this request is for |
| 761 | * @clk_id: Clock identifier for the device for this request. |
| 762 | * Each device has its own set of clock inputs. This indexes |
| 763 | * which clock input to modify. |
| 764 | * @req_state: state indicating if the clock is managed by us and enabled |
| 765 | * @curr_state: state indicating if the clock is ready for operation |
| 766 | * |
| 767 | * Return: 0 if all goes well, else appropriate error message |
| 768 | */ |
| 769 | int ti_sci_clock_is_on(uint32_t dev_id, uint8_t clk_id, |
| 770 | bool *req_state, bool *curr_state) |
| 771 | { |
| 772 | uint8_t c_state = 0, r_state = 0; |
| 773 | int ret; |
| 774 | |
| 775 | if (!req_state && !curr_state) |
| 776 | return -EINVAL; |
| 777 | |
| 778 | ret = ti_sci_clock_get_state(dev_id, clk_id, &r_state, &c_state); |
| 779 | if (ret) |
| 780 | return ret; |
| 781 | |
| 782 | if (req_state) |
| 783 | *req_state = (r_state == MSG_CLOCK_SW_STATE_REQ); |
| 784 | if (curr_state) |
| 785 | *curr_state = (c_state == MSG_CLOCK_HW_STATE_READY); |
| 786 | |
| 787 | return 0; |
| 788 | } |
| 789 | |
| 790 | /** |
| 791 | * ti_sci_clock_is_off() - Is the clock OFF |
| 792 | * |
| 793 | * @dev_id: Device identifier this request is for |
| 794 | * @clk_id: Clock identifier for the device for this request. |
| 795 | * Each device has its own set of clock inputs. This indexes |
| 796 | * which clock input to modify. |
| 797 | * @req_state: state indicating if the clock is managed by us and disabled |
| 798 | * @curr_state: state indicating if the clock is NOT ready for operation |
| 799 | * |
| 800 | * Return: 0 if all goes well, else appropriate error message |
| 801 | */ |
| 802 | int ti_sci_clock_is_off(uint32_t dev_id, uint8_t clk_id, |
| 803 | bool *req_state, bool *curr_state) |
| 804 | { |
| 805 | uint8_t c_state = 0, r_state = 0; |
| 806 | int ret; |
| 807 | |
| 808 | if (!req_state && !curr_state) |
| 809 | return -EINVAL; |
| 810 | |
| 811 | ret = ti_sci_clock_get_state(dev_id, clk_id, &r_state, &c_state); |
| 812 | if (ret) |
| 813 | return ret; |
| 814 | |
| 815 | if (req_state) |
| 816 | *req_state = (r_state == MSG_CLOCK_SW_STATE_UNREQ); |
| 817 | if (curr_state) |
| 818 | *curr_state = (c_state == MSG_CLOCK_HW_STATE_NOT_READY); |
| 819 | |
| 820 | return 0; |
| 821 | } |
| 822 | |
| 823 | /** |
| 824 | * ti_sci_clock_set_parent() - Set the clock source of a specific device clock |
| 825 | * |
| 826 | * @dev_id: Device identifier this request is for |
| 827 | * @clk_id: Clock identifier for the device for this request. |
| 828 | * Each device has its own set of clock inputs. This indexes |
| 829 | * which clock input to modify. |
| 830 | * @parent_id: Parent clock identifier to set |
| 831 | * |
| 832 | * Return: 0 if all goes well, else appropriate error message |
| 833 | */ |
| 834 | int ti_sci_clock_set_parent(uint32_t dev_id, uint8_t clk_id, uint8_t parent_id) |
| 835 | { |
| 836 | struct ti_sci_msg_req_set_clock_parent req; |
| 837 | struct ti_sci_msg_hdr resp; |
| 838 | |
| 839 | struct ti_sci_xfer xfer; |
| 840 | int ret; |
| 841 | |
| 842 | ret = ti_sci_setup_one_xfer(TI_SCI_MSG_SET_CLOCK_PARENT, |
| 843 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 844 | &req, sizeof(req), |
| 845 | &resp, sizeof(resp), |
| 846 | &xfer); |
| 847 | if (ret) { |
| 848 | ERROR("Message alloc failed (%d)\n", ret); |
| 849 | return ret; |
| 850 | } |
| 851 | |
| 852 | req.dev_id = dev_id; |
| 853 | req.clk_id = clk_id; |
| 854 | req.parent_id = parent_id; |
| 855 | |
| 856 | ret = ti_sci_do_xfer(&xfer); |
| 857 | if (ret) { |
| 858 | ERROR("Transfer send failed (%d)\n", ret); |
| 859 | return ret; |
| 860 | } |
| 861 | |
| 862 | if (!ti_sci_is_response_ack(&resp)) |
| 863 | return -ENODEV; |
| 864 | |
| 865 | return 0; |
| 866 | } |
| 867 | |
| 868 | /** |
| 869 | * ti_sci_clock_get_parent() - Get current parent clock source |
| 870 | * |
| 871 | * @dev_id: Device identifier this request is for |
| 872 | * @clk_id: Clock identifier for the device for this request. |
| 873 | * Each device has its own set of clock inputs. This indexes |
| 874 | * which clock input to modify. |
| 875 | * @parent_id: Current clock parent |
| 876 | * |
| 877 | * Return: 0 if all goes well, else appropriate error message |
| 878 | */ |
| 879 | int ti_sci_clock_get_parent(uint32_t dev_id, uint8_t clk_id, uint8_t *parent_id) |
| 880 | { |
| 881 | struct ti_sci_msg_req_get_clock_parent req; |
| 882 | struct ti_sci_msg_resp_get_clock_parent resp; |
| 883 | |
| 884 | struct ti_sci_xfer xfer; |
| 885 | int ret; |
| 886 | |
| 887 | ret = ti_sci_setup_one_xfer(TI_SCI_MSG_GET_CLOCK_PARENT, |
| 888 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 889 | &req, sizeof(req), |
| 890 | &resp, sizeof(resp), |
| 891 | &xfer); |
| 892 | if (ret) { |
| 893 | ERROR("Message alloc failed (%d)\n", ret); |
| 894 | return ret; |
| 895 | } |
| 896 | |
| 897 | req.dev_id = dev_id; |
| 898 | req.clk_id = clk_id; |
| 899 | |
| 900 | ret = ti_sci_do_xfer(&xfer); |
| 901 | if (ret) { |
| 902 | ERROR("Transfer send failed (%d)\n", ret); |
| 903 | return ret; |
| 904 | } |
| 905 | |
| 906 | if (!ti_sci_is_response_ack(&resp)) |
| 907 | return -ENODEV; |
| 908 | |
| 909 | *parent_id = resp.parent_id; |
| 910 | |
| 911 | return 0; |
| 912 | } |
| 913 | |
| 914 | /** |
| 915 | * ti_sci_clock_get_num_parents() - Get num parents of the current clk source |
| 916 | * |
| 917 | * @dev_id: Device identifier this request is for |
| 918 | * @clk_id: Clock identifier for the device for this request. |
| 919 | * Each device has its own set of clock inputs. This indexes |
| 920 | * which clock input to modify. |
| 921 | * @num_parents: Returns he number of parents to the current clock. |
| 922 | * |
| 923 | * Return: 0 if all goes well, else appropriate error message |
| 924 | */ |
| 925 | int ti_sci_clock_get_num_parents(uint32_t dev_id, uint8_t clk_id, |
| 926 | uint8_t *num_parents) |
| 927 | { |
| 928 | struct ti_sci_msg_req_get_clock_num_parents req; |
| 929 | struct ti_sci_msg_resp_get_clock_num_parents resp; |
| 930 | |
| 931 | struct ti_sci_xfer xfer; |
| 932 | int ret; |
| 933 | |
| 934 | ret = ti_sci_setup_one_xfer(TI_SCI_MSG_GET_NUM_CLOCK_PARENTS, |
| 935 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 936 | &req, sizeof(req), |
| 937 | &resp, sizeof(resp), |
| 938 | &xfer); |
| 939 | if (ret) { |
| 940 | ERROR("Message alloc failed (%d)\n", ret); |
| 941 | return ret; |
| 942 | } |
| 943 | |
| 944 | req.dev_id = dev_id; |
| 945 | req.clk_id = clk_id; |
| 946 | |
| 947 | ret = ti_sci_do_xfer(&xfer); |
| 948 | if (ret) { |
| 949 | ERROR("Transfer send failed (%d)\n", ret); |
| 950 | return ret; |
| 951 | } |
| 952 | |
| 953 | if (!ti_sci_is_response_ack(&resp)) |
| 954 | return -ENODEV; |
| 955 | |
| 956 | *num_parents = resp.num_parents; |
| 957 | |
| 958 | return 0; |
| 959 | } |
| 960 | |
| 961 | /** |
| 962 | * ti_sci_clock_get_match_freq() - Find a good match for frequency |
| 963 | * |
| 964 | * @dev_id: Device identifier this request is for |
| 965 | * @clk_id: Clock identifier for the device for this request. |
| 966 | * Each device has its own set of clock inputs. This indexes |
| 967 | * which clock input to modify. |
| 968 | * @min_freq: The minimum allowable frequency in Hz. This is the minimum |
| 969 | * allowable programmed frequency and does not account for clock |
| 970 | * tolerances and jitter. |
| 971 | * @target_freq: The target clock frequency in Hz. A frequency will be |
| 972 | * processed as close to this target frequency as possible. |
| 973 | * @max_freq: The maximum allowable frequency in Hz. This is the maximum |
| 974 | * allowable programmed frequency and does not account for clock |
| 975 | * tolerances and jitter. |
| 976 | * @match_freq: Frequency match in Hz response. |
| 977 | * |
| 978 | * Return: 0 if all goes well, else appropriate error message |
| 979 | */ |
| 980 | int ti_sci_clock_get_match_freq(uint32_t dev_id, uint8_t clk_id, |
| 981 | uint64_t min_freq, uint64_t target_freq, |
| 982 | uint64_t max_freq, uint64_t *match_freq) |
| 983 | { |
| 984 | struct ti_sci_msg_req_query_clock_freq req; |
| 985 | struct ti_sci_msg_resp_query_clock_freq resp; |
| 986 | |
| 987 | struct ti_sci_xfer xfer; |
| 988 | int ret; |
| 989 | |
| 990 | ret = ti_sci_setup_one_xfer(TI_SCI_MSG_QUERY_CLOCK_FREQ, |
| 991 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 992 | &req, sizeof(req), |
| 993 | &resp, sizeof(resp), |
| 994 | &xfer); |
| 995 | if (ret) { |
| 996 | ERROR("Message alloc failed (%d)\n", ret); |
| 997 | return ret; |
| 998 | } |
| 999 | |
| 1000 | req.dev_id = dev_id; |
| 1001 | req.clk_id = clk_id; |
| 1002 | req.min_freq_hz = min_freq; |
| 1003 | req.target_freq_hz = target_freq; |
| 1004 | req.max_freq_hz = max_freq; |
| 1005 | |
| 1006 | ret = ti_sci_do_xfer(&xfer); |
| 1007 | if (ret) { |
| 1008 | ERROR("Transfer send failed (%d)\n", ret); |
| 1009 | return ret; |
| 1010 | } |
| 1011 | |
| 1012 | if (!ti_sci_is_response_ack(&resp)) |
| 1013 | return -ENODEV; |
| 1014 | |
| 1015 | *match_freq = resp.freq_hz; |
| 1016 | |
| 1017 | return 0; |
| 1018 | } |
| 1019 | |
| 1020 | /** |
| 1021 | * ti_sci_clock_set_freq() - Set a frequency for clock |
| 1022 | * |
| 1023 | * @dev_id: Device identifier this request is for |
| 1024 | * @clk_id: Clock identifier for the device for this request. |
| 1025 | * Each device has its own set of clock inputs. This indexes |
| 1026 | * which clock input to modify. |
| 1027 | * @min_freq: The minimum allowable frequency in Hz. This is the minimum |
| 1028 | * allowable programmed frequency and does not account for clock |
| 1029 | * tolerances and jitter. |
| 1030 | * @target_freq: The target clock frequency in Hz. A frequency will be |
| 1031 | * processed as close to this target frequency as possible. |
| 1032 | * @max_freq: The maximum allowable frequency in Hz. This is the maximum |
| 1033 | * allowable programmed frequency and does not account for clock |
| 1034 | * tolerances and jitter. |
| 1035 | * |
| 1036 | * Return: 0 if all goes well, else appropriate error message |
| 1037 | */ |
| 1038 | int ti_sci_clock_set_freq(uint32_t dev_id, uint8_t clk_id, uint64_t min_freq, |
| 1039 | uint64_t target_freq, uint64_t max_freq) |
| 1040 | { |
| 1041 | struct ti_sci_msg_req_set_clock_freq req; |
| 1042 | struct ti_sci_msg_hdr resp; |
| 1043 | |
| 1044 | struct ti_sci_xfer xfer; |
| 1045 | int ret; |
| 1046 | |
| 1047 | ret = ti_sci_setup_one_xfer(TI_SCI_MSG_SET_CLOCK_FREQ, |
| 1048 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 1049 | &req, sizeof(req), |
| 1050 | &resp, sizeof(resp), |
| 1051 | &xfer); |
| 1052 | if (ret) { |
| 1053 | ERROR("Message alloc failed (%d)\n", ret); |
| 1054 | return ret; |
| 1055 | } |
| 1056 | req.dev_id = dev_id; |
| 1057 | req.clk_id = clk_id; |
| 1058 | req.min_freq_hz = min_freq; |
| 1059 | req.target_freq_hz = target_freq; |
| 1060 | req.max_freq_hz = max_freq; |
| 1061 | |
| 1062 | ret = ti_sci_do_xfer(&xfer); |
| 1063 | if (ret) { |
| 1064 | ERROR("Transfer send failed (%d)\n", ret); |
| 1065 | return ret; |
| 1066 | } |
| 1067 | |
| 1068 | if (!ti_sci_is_response_ack(&resp)) |
| 1069 | return -ENODEV; |
| 1070 | |
| 1071 | return 0; |
| 1072 | } |
| 1073 | |
| 1074 | /** |
| 1075 | * ti_sci_clock_get_freq() - Get current frequency |
| 1076 | * |
| 1077 | * @dev_id: Device identifier this request is for |
| 1078 | * @clk_id: Clock identifier for the device for this request. |
| 1079 | * Each device has its own set of clock inputs. This indexes |
| 1080 | * which clock input to modify. |
| 1081 | * @freq: Currently frequency in Hz |
| 1082 | * |
| 1083 | * Return: 0 if all goes well, else appropriate error message |
| 1084 | */ |
| 1085 | int ti_sci_clock_get_freq(uint32_t dev_id, uint8_t clk_id, uint64_t *freq) |
| 1086 | { |
| 1087 | struct ti_sci_msg_req_get_clock_freq req; |
| 1088 | struct ti_sci_msg_resp_get_clock_freq resp; |
| 1089 | |
| 1090 | struct ti_sci_xfer xfer; |
| 1091 | int ret; |
| 1092 | |
| 1093 | ret = ti_sci_setup_one_xfer(TI_SCI_MSG_GET_CLOCK_FREQ, |
| 1094 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 1095 | &req, sizeof(req), |
| 1096 | &resp, sizeof(resp), |
| 1097 | &xfer); |
| 1098 | if (ret) { |
| 1099 | ERROR("Message alloc failed (%d)\n", ret); |
| 1100 | return ret; |
| 1101 | } |
| 1102 | |
| 1103 | req.dev_id = dev_id; |
| 1104 | req.clk_id = clk_id; |
| 1105 | |
| 1106 | ret = ti_sci_do_xfer(&xfer); |
| 1107 | if (ret) { |
| 1108 | ERROR("Transfer send failed (%d)\n", ret); |
| 1109 | return ret; |
| 1110 | } |
| 1111 | |
| 1112 | if (!ti_sci_is_response_ack(&resp)) |
| 1113 | return -ENODEV; |
| 1114 | |
| 1115 | *freq = resp.freq_hz; |
| 1116 | |
| 1117 | return 0; |
| 1118 | } |
| 1119 | |
| 1120 | /** |
Andrew F. Davis | 0d44930 | 2018-05-04 19:06:12 +0000 | [diff] [blame] | 1121 | * ti_sci_core_reboot() - Command to request system reset |
| 1122 | * |
| 1123 | * Return: 0 if all goes well, else appropriate error message |
| 1124 | */ |
| 1125 | int ti_sci_core_reboot(void) |
| 1126 | { |
| 1127 | struct ti_sci_msg_req_reboot req; |
| 1128 | struct ti_sci_msg_hdr resp; |
| 1129 | |
| 1130 | struct ti_sci_xfer xfer; |
| 1131 | int ret; |
| 1132 | |
| 1133 | ret = ti_sci_setup_one_xfer(TI_SCI_MSG_SYS_RESET, |
| 1134 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 1135 | &req, sizeof(req), |
| 1136 | &resp, sizeof(resp), |
| 1137 | &xfer); |
| 1138 | if (ret) { |
| 1139 | ERROR("Message alloc failed (%d)\n", ret); |
| 1140 | return ret; |
| 1141 | } |
| 1142 | |
| 1143 | ret = ti_sci_do_xfer(&xfer); |
| 1144 | if (ret) { |
| 1145 | ERROR("Transfer send failed (%d)\n", ret); |
| 1146 | return ret; |
| 1147 | } |
| 1148 | |
| 1149 | if (!ti_sci_is_response_ack(&resp)) |
| 1150 | return -ENODEV; |
| 1151 | |
| 1152 | return 0; |
| 1153 | } |
| 1154 | |
| 1155 | /** |
Andrew F. Davis | d92fdfb | 2018-05-04 19:06:13 +0000 | [diff] [blame] | 1156 | * ti_sci_proc_request() - Request a physical processor control |
| 1157 | * |
| 1158 | * @proc_id: Processor ID this request is for |
| 1159 | * |
| 1160 | * Return: 0 if all goes well, else appropriate error message |
| 1161 | */ |
| 1162 | int ti_sci_proc_request(uint8_t proc_id) |
| 1163 | { |
| 1164 | struct ti_sci_msg_req_proc_request req; |
| 1165 | struct ti_sci_msg_hdr resp; |
| 1166 | |
| 1167 | struct ti_sci_xfer xfer; |
| 1168 | int ret; |
| 1169 | |
| 1170 | ret = ti_sci_setup_one_xfer(TISCI_MSG_PROC_REQUEST, |
| 1171 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 1172 | &req, sizeof(req), |
| 1173 | &resp, sizeof(resp), |
| 1174 | &xfer); |
| 1175 | if (ret) { |
| 1176 | ERROR("Message alloc failed (%d)\n", ret); |
| 1177 | return ret; |
| 1178 | } |
| 1179 | |
| 1180 | req.processor_id = proc_id; |
| 1181 | |
| 1182 | ret = ti_sci_do_xfer(&xfer); |
| 1183 | if (ret) { |
| 1184 | ERROR("Transfer send failed (%d)\n", ret); |
| 1185 | return ret; |
| 1186 | } |
| 1187 | |
| 1188 | if (!ti_sci_is_response_ack(&resp)) |
| 1189 | return -ENODEV; |
| 1190 | |
| 1191 | return 0; |
| 1192 | } |
| 1193 | |
| 1194 | /** |
| 1195 | * ti_sci_proc_release() - Release a physical processor control |
| 1196 | * |
| 1197 | * @proc_id: Processor ID this request is for |
| 1198 | * |
| 1199 | * Return: 0 if all goes well, else appropriate error message |
| 1200 | */ |
| 1201 | int ti_sci_proc_release(uint8_t proc_id) |
| 1202 | { |
| 1203 | struct ti_sci_msg_req_proc_release req; |
| 1204 | struct ti_sci_msg_hdr resp; |
| 1205 | |
| 1206 | struct ti_sci_xfer xfer; |
| 1207 | int ret; |
| 1208 | |
| 1209 | ret = ti_sci_setup_one_xfer(TISCI_MSG_PROC_RELEASE, |
| 1210 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 1211 | &req, sizeof(req), |
| 1212 | &resp, sizeof(resp), |
| 1213 | &xfer); |
| 1214 | if (ret) { |
| 1215 | ERROR("Message alloc failed (%d)\n", ret); |
| 1216 | return ret; |
| 1217 | } |
| 1218 | |
| 1219 | req.processor_id = proc_id; |
| 1220 | |
| 1221 | ret = ti_sci_do_xfer(&xfer); |
| 1222 | if (ret) { |
| 1223 | ERROR("Transfer send failed (%d)\n", ret); |
| 1224 | return ret; |
| 1225 | } |
| 1226 | |
| 1227 | if (!ti_sci_is_response_ack(&resp)) |
| 1228 | return -ENODEV; |
| 1229 | |
| 1230 | return 0; |
| 1231 | } |
| 1232 | |
| 1233 | /** |
| 1234 | * ti_sci_proc_handover() - Handover a physical processor control to a host in |
| 1235 | * the processor's access control list. |
| 1236 | * |
| 1237 | * @proc_id: Processor ID this request is for |
| 1238 | * @host_id: Host ID to get the control of the processor |
| 1239 | * |
| 1240 | * Return: 0 if all goes well, else appropriate error message |
| 1241 | */ |
| 1242 | int ti_sci_proc_handover(uint8_t proc_id, uint8_t host_id) |
| 1243 | { |
| 1244 | struct ti_sci_msg_req_proc_handover req; |
| 1245 | struct ti_sci_msg_hdr resp; |
| 1246 | |
| 1247 | struct ti_sci_xfer xfer; |
| 1248 | int ret; |
| 1249 | |
| 1250 | ret = ti_sci_setup_one_xfer(TISCI_MSG_PROC_HANDOVER, |
| 1251 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 1252 | &req, sizeof(req), |
| 1253 | &resp, sizeof(resp), |
| 1254 | &xfer); |
| 1255 | if (ret) { |
| 1256 | ERROR("Message alloc failed (%d)\n", ret); |
| 1257 | return ret; |
| 1258 | } |
| 1259 | |
| 1260 | req.processor_id = proc_id; |
| 1261 | req.host_id = host_id; |
| 1262 | |
| 1263 | ret = ti_sci_do_xfer(&xfer); |
| 1264 | if (ret) { |
| 1265 | ERROR("Transfer send failed (%d)\n", ret); |
| 1266 | return ret; |
| 1267 | } |
| 1268 | |
| 1269 | if (!ti_sci_is_response_ack(&resp)) |
| 1270 | return -ENODEV; |
| 1271 | |
| 1272 | return 0; |
| 1273 | } |
| 1274 | |
| 1275 | /** |
| 1276 | * ti_sci_proc_set_boot_cfg() - Set the processor boot configuration flags |
| 1277 | * |
| 1278 | * @proc_id: Processor ID this request is for |
| 1279 | * @config_flags_set: Configuration flags to be set |
| 1280 | * @config_flags_clear: Configuration flags to be cleared |
| 1281 | * |
| 1282 | * Return: 0 if all goes well, else appropriate error message |
| 1283 | */ |
| 1284 | int ti_sci_proc_set_boot_cfg(uint8_t proc_id, uint64_t bootvector, |
| 1285 | uint32_t config_flags_set, |
| 1286 | uint32_t config_flags_clear) |
| 1287 | { |
| 1288 | struct ti_sci_msg_req_set_proc_boot_config req; |
| 1289 | struct ti_sci_msg_hdr resp; |
| 1290 | |
| 1291 | struct ti_sci_xfer xfer; |
| 1292 | int ret; |
| 1293 | |
| 1294 | ret = ti_sci_setup_one_xfer(TISCI_MSG_SET_PROC_BOOT_CONFIG, |
| 1295 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 1296 | &req, sizeof(req), |
| 1297 | &resp, sizeof(resp), |
| 1298 | &xfer); |
| 1299 | if (ret) { |
| 1300 | ERROR("Message alloc failed (%d)\n", ret); |
| 1301 | return ret; |
| 1302 | } |
| 1303 | |
| 1304 | req.processor_id = proc_id; |
| 1305 | req.bootvector_low = bootvector & TISCI_ADDR_LOW_MASK; |
| 1306 | req.bootvector_high = (bootvector & TISCI_ADDR_HIGH_MASK) >> |
| 1307 | TISCI_ADDR_HIGH_SHIFT; |
| 1308 | req.config_flags_set = config_flags_set; |
| 1309 | req.config_flags_clear = config_flags_clear; |
| 1310 | |
| 1311 | ret = ti_sci_do_xfer(&xfer); |
| 1312 | if (ret) { |
| 1313 | ERROR("Transfer send failed (%d)\n", ret); |
| 1314 | return ret; |
| 1315 | } |
| 1316 | |
| 1317 | if (!ti_sci_is_response_ack(&resp)) |
| 1318 | return -ENODEV; |
| 1319 | |
| 1320 | return 0; |
| 1321 | } |
| 1322 | |
| 1323 | /** |
| 1324 | * ti_sci_proc_set_boot_ctrl() - Set the processor boot control flags |
| 1325 | * |
| 1326 | * @proc_id: Processor ID this request is for |
| 1327 | * @control_flags_set: Control flags to be set |
| 1328 | * @control_flags_clear: Control flags to be cleared |
| 1329 | * |
| 1330 | * Return: 0 if all goes well, else appropriate error message |
| 1331 | */ |
| 1332 | int ti_sci_proc_set_boot_ctrl(uint8_t proc_id, uint32_t control_flags_set, |
| 1333 | uint32_t control_flags_clear) |
| 1334 | { |
| 1335 | struct ti_sci_msg_req_set_proc_boot_ctrl req; |
| 1336 | struct ti_sci_msg_hdr resp; |
| 1337 | |
| 1338 | struct ti_sci_xfer xfer; |
| 1339 | int ret; |
| 1340 | |
| 1341 | ret = ti_sci_setup_one_xfer(TISCI_MSG_SET_PROC_BOOT_CTRL, |
| 1342 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 1343 | &req, sizeof(req), |
| 1344 | &resp, sizeof(resp), |
| 1345 | &xfer); |
| 1346 | if (ret) { |
| 1347 | ERROR("Message alloc failed (%d)\n", ret); |
| 1348 | return ret; |
| 1349 | } |
| 1350 | |
| 1351 | req.processor_id = proc_id; |
| 1352 | req.control_flags_set = control_flags_set; |
| 1353 | req.control_flags_clear = control_flags_clear; |
| 1354 | |
| 1355 | ret = ti_sci_do_xfer(&xfer); |
| 1356 | if (ret) { |
| 1357 | ERROR("Transfer send failed (%d)\n", ret); |
| 1358 | return ret; |
| 1359 | } |
| 1360 | |
| 1361 | if (!ti_sci_is_response_ack(&resp)) |
| 1362 | return -ENODEV; |
| 1363 | |
| 1364 | return 0; |
| 1365 | } |
| 1366 | |
| 1367 | /** |
| 1368 | * ti_sci_proc_auth_boot_image() - Authenticate and load image and then set the |
| 1369 | * processor configuration flags |
| 1370 | * |
| 1371 | * @proc_id: Processor ID this request is for |
| 1372 | * @cert_addr: Memory address at which payload image certificate is located |
| 1373 | * |
| 1374 | * Return: 0 if all goes well, else appropriate error message |
| 1375 | */ |
| 1376 | int ti_sci_proc_auth_boot_image(uint8_t proc_id, uint64_t cert_addr) |
| 1377 | { |
| 1378 | struct ti_sci_msg_req_proc_auth_boot_image req; |
| 1379 | struct ti_sci_msg_hdr resp; |
| 1380 | |
| 1381 | struct ti_sci_xfer xfer; |
| 1382 | int ret; |
| 1383 | |
| 1384 | ret = ti_sci_setup_one_xfer(TISCI_MSG_PROC_AUTH_BOOT_IMIAGE, |
| 1385 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 1386 | &req, sizeof(req), |
| 1387 | &resp, sizeof(resp), |
| 1388 | &xfer); |
| 1389 | if (ret) { |
| 1390 | ERROR("Message alloc failed (%d)\n", ret); |
| 1391 | return ret; |
| 1392 | } |
| 1393 | |
| 1394 | req.processor_id = proc_id; |
| 1395 | req.cert_addr_low = cert_addr & TISCI_ADDR_LOW_MASK; |
| 1396 | req.cert_addr_high = (cert_addr & TISCI_ADDR_HIGH_MASK) >> |
| 1397 | TISCI_ADDR_HIGH_SHIFT; |
| 1398 | |
| 1399 | ret = ti_sci_do_xfer(&xfer); |
| 1400 | if (ret) { |
| 1401 | ERROR("Transfer send failed (%d)\n", ret); |
| 1402 | return ret; |
| 1403 | } |
| 1404 | |
| 1405 | if (!ti_sci_is_response_ack(&resp)) |
| 1406 | return -ENODEV; |
| 1407 | |
| 1408 | return 0; |
| 1409 | } |
| 1410 | |
| 1411 | /** |
| 1412 | * ti_sci_proc_get_boot_status() - Get the processor boot status |
| 1413 | * |
| 1414 | * @proc_id: Processor ID this request is for |
| 1415 | * |
| 1416 | * Return: 0 if all goes well, else appropriate error message |
| 1417 | */ |
| 1418 | int ti_sci_proc_get_boot_status(uint8_t proc_id, uint64_t *bv, |
| 1419 | uint32_t *cfg_flags, |
| 1420 | uint32_t *ctrl_flags, |
| 1421 | uint32_t *sts_flags) |
| 1422 | { |
| 1423 | struct ti_sci_msg_req_get_proc_boot_status req; |
| 1424 | struct ti_sci_msg_resp_get_proc_boot_status resp; |
| 1425 | |
| 1426 | struct ti_sci_xfer xfer; |
| 1427 | int ret; |
| 1428 | |
| 1429 | ret = ti_sci_setup_one_xfer(TISCI_MSG_GET_PROC_BOOT_STATUS, |
| 1430 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 1431 | &req, sizeof(req), |
| 1432 | &resp, sizeof(resp), |
| 1433 | &xfer); |
| 1434 | if (ret) { |
| 1435 | ERROR("Message alloc failed (%d)\n", ret); |
| 1436 | return ret; |
| 1437 | } |
| 1438 | |
| 1439 | req.processor_id = proc_id; |
| 1440 | |
| 1441 | ret = ti_sci_do_xfer(&xfer); |
| 1442 | if (ret) { |
| 1443 | ERROR("Transfer send failed (%d)\n", ret); |
| 1444 | return ret; |
| 1445 | } |
| 1446 | |
| 1447 | if (!ti_sci_is_response_ack(&resp)) |
| 1448 | return -ENODEV; |
| 1449 | |
| 1450 | *bv = (resp.bootvector_low & TISCI_ADDR_LOW_MASK) | |
| 1451 | (((uint64_t)resp.bootvector_high << TISCI_ADDR_HIGH_SHIFT) & |
| 1452 | TISCI_ADDR_HIGH_MASK); |
| 1453 | *cfg_flags = resp.config_flags; |
| 1454 | *ctrl_flags = resp.control_flags; |
| 1455 | *sts_flags = resp.status_flags; |
| 1456 | |
| 1457 | return 0; |
| 1458 | } |
| 1459 | |
| 1460 | /** |
Andrew F. Davis | a513b2a | 2018-05-04 19:06:09 +0000 | [diff] [blame] | 1461 | * ti_sci_init() - Basic initialization |
| 1462 | * |
| 1463 | * Return: 0 if all goes well, else appropriate error message |
| 1464 | */ |
| 1465 | int ti_sci_init(void) |
| 1466 | { |
| 1467 | struct ti_sci_msg_resp_version rev_info; |
| 1468 | int ret; |
| 1469 | |
| 1470 | ret = ti_sci_get_revision(&rev_info); |
| 1471 | if (ret) { |
| 1472 | ERROR("Unable to communicate with control firmware (%d)\n", ret); |
| 1473 | return ret; |
| 1474 | } |
| 1475 | |
| 1476 | INFO("SYSFW ABI: %d.%d (firmware rev 0x%04x '%s')\n", |
| 1477 | rev_info.abi_major, rev_info.abi_minor, |
| 1478 | rev_info.firmware_revision, |
| 1479 | rev_info.firmware_description); |
| 1480 | |
| 1481 | return 0; |
| 1482 | } |