From: Lokesh Vutla Date: Tue, 20 Aug 2019 15:07:32 +0000 (+0530) Subject: tisci: Add support for handling devices X-Git-Tag: v0.1~22 X-Git-Url: https://git.ti.com/gitweb?p=k3conf%2Fk3conf.git;a=commitdiff_plain;h=d8a9e75417e67dff0086c661d15bf6e936440d39 tisci: Add support for handling devices Add support for the following tisci commands for handling devices: - ti_sci_cmd_enable_device - ti_sci_cmd_disable_device - ti_sci_get_device_status Signed-off-by: Lokesh Vutla --- diff --git a/Makefile b/Makefile index 3f51dec..b06a829 100644 --- a/Makefile +++ b/Makefile @@ -62,7 +62,8 @@ COMMONSOURCES=\ common/mmio.c \ common/socinfo.c \ common/sec_proxy.c \ - common/tisci/tisci_core.c + common/tisci/tisci_core.c \ + common/tisci/tisci_device.c COMMONOBJECTS= $(COMMONSOURCES:.c=.o) diff --git a/common/tisci/tisci_device.c b/common/tisci/tisci_device.c new file mode 100644 index 0000000..cc0fd1e --- /dev/null +++ b/common/tisci/tisci_device.c @@ -0,0 +1,98 @@ +/* + * TISCI device ops library + * + * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/ + * Lokesh Vutla + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +static const char device_state[MAX_DEVICE_HW_STATES + 1][MAX_DEVICE_STATE_LENGTH] = { + [MSG_DEVICE_HW_STATE_OFF] = "DEVICE_STATE_OFF", + [MSG_DEVICE_HW_STATE_ON] = "DEVICE_STATE_ON", + [MSG_DEVICE_HW_STATE_TRANS] = "DEVICE_STATE_TRANS", + [MAX_DEVICE_HW_STATES] = "DEVICE_STATE_UNKNOWN" +}; + +static int ti_sci_set_device_state(uint32_t id, uint32_t flags, uint8_t state) +{ + struct ti_sci_msg_req_set_device_state *req; + uint8_t buf[SEC_PROXY_MAX_MSG_SIZE]; + struct k3_sec_proxy_msg msg; + + memset(buf, 0, sizeof(buf)); + ti_sci_setup_header((struct ti_sci_msg_hdr *)buf, + TI_SCI_MSG_SET_DEVICE_STATE, flags); + req = (struct ti_sci_msg_req_set_device_state *)buf; + req->id = id; + req->state = state; + + msg.len = sizeof(*req); + msg.buf = buf; + return ti_sci_xfer_msg(&msg); +} + +int ti_sci_cmd_enable_device(uint32_t dev_id) +{ + return ti_sci_set_device_state(dev_id, 0, MSG_DEVICE_SW_STATE_ON); +} + +int ti_sci_cmd_disable_device(uint32_t dev_id) +{ + return ti_sci_set_device_state(dev_id, 0, MSG_DEVICE_SW_STATE_AUTO_OFF); +} + +const char *ti_sci_cmd_get_device_status(uint32_t dev_id) +{ + struct ti_sci_msg_resp_get_device_state *resp; + struct ti_sci_msg_req_get_device_state *req; + uint8_t buf[SEC_PROXY_MAX_MSG_SIZE]; + struct k3_sec_proxy_msg msg; + int ret = 0; + + memset(buf, 0, sizeof(buf)); + ti_sci_setup_header((struct ti_sci_msg_hdr *)buf, + TI_SCI_MSG_GET_DEVICE_STATE, 0); + req = (struct ti_sci_msg_req_get_device_state *)buf; + req->id = dev_id; + + msg.len = sizeof(*req); + msg.buf = buf; + ret = ti_sci_xfer_msg(&msg); + if (ret) + return NULL; + + resp = (struct ti_sci_msg_resp_get_device_state *)buf; + + return device_state[resp->current_state]; +} diff --git a/include/tisci.h b/include/tisci.h index 43faefe..c339de7 100644 --- a/include/tisci.h +++ b/include/tisci.h @@ -50,5 +50,11 @@ struct ti_sci_info { struct ti_sci_version_info version; }; +#define MAX_DEVICE_STATE_LENGTH 25 + int ti_sci_init(void); +const char *ti_sci_cmd_get_device_status(uint32_t dev_id); +int ti_sci_cmd_disable_device(uint32_t dev_id); +int ti_sci_cmd_enable_device(uint32_t dev_id); + #endif diff --git a/include/tisci_protocol.h b/include/tisci_protocol.h index b40baec..78dec07 100644 --- a/include/tisci_protocol.h +++ b/include/tisci_protocol.h @@ -40,6 +40,9 @@ #include #define TI_SCI_MSG_VERSION 0x0002 +/* Device requests */ +#define TI_SCI_MSG_SET_DEVICE_STATE 0x0200 +#define TI_SCI_MSG_GET_DEVICE_STATE 0x0201 #define TI_SCI_MSG_FLAG(val) (1 << (val)) #define TI_SCI_FLAG_REQ_GENERIC_NORESPONSE 0x0 @@ -68,6 +71,39 @@ struct ti_sci_secure_msg_hdr { uint16_t reserved; } __attribute__ ((__packed__)); +struct ti_sci_msg_req_set_device_state { + /* Additional hdr->flags options */ +#define MSG_FLAG_DEVICE_WAKE_ENABLED TI_SCI_MSG_FLAG(8) +#define MSG_FLAG_DEVICE_RESET_ISO TI_SCI_MSG_FLAG(9) +#define MSG_FLAG_DEVICE_EXCLUSIVE TI_SCI_MSG_FLAG(10) + struct ti_sci_msg_hdr hdr; + uint32_t id; + uint32_t reserved; +#define MSG_DEVICE_SW_STATE_AUTO_OFF 0 +#define MSG_DEVICE_SW_STATE_RETENTION 1 +#define MSG_DEVICE_SW_STATE_ON 2 + uint8_t state; +} __attribute__ ((__packed__)); + +struct ti_sci_msg_req_get_device_state { + struct ti_sci_msg_hdr hdr; + uint32_t id; +} __attribute__ ((__packed__)); + +struct ti_sci_msg_resp_get_device_state { + struct ti_sci_msg_hdr hdr; + uint32_t context_loss_count; + uint32_t resets; + uint8_t programmed_state; +#define MSG_DEVICE_HW_STATE_OFF 0 +#define MSG_DEVICE_HW_STATE_ON 1 +#define MSG_DEVICE_HW_STATE_TRANS 2 +#define MAX_DEVICE_HW_STATES 3 + uint8_t current_state; +} __attribute__ ((__packed__)); + +void ti_sci_setup_header(struct ti_sci_msg_hdr *hdr, uint16_t type, + uint32_t flags); int ti_sci_xfer_msg(struct k3_sec_proxy_msg *msg); static inline uint8_t ti_sci_is_response_ack(uint8_t *resp)