firmware: Add support for querying msmc memory
authorLokesh Vutla <lokeshvutla@ti.com>
Fri, 8 Mar 2019 06:17:32 +0000 (11:47 +0530)
committerTom Rini <trini@konsulko.com>
Fri, 12 Apr 2019 12:05:50 +0000 (08:05 -0400)
DMSC can use certain amount of msmc memory available in the
system. Also certain part of msmc memory can be marked as L3
cache using board config. But users might not know what size
is being used and the remaining available msmc memory. In order
to fix this TISCI protocol provides a messages that can query
the available msmc memory in the system. Add support for this
message.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
drivers/firmware/ti_sci.c
drivers/firmware/ti_sci.h
include/linux/soc/ti/ti_sci_protocol.h

index ec78a520e702cc711677d72d82953e31c1ecb38f..d47d22fff3e4661e36bbbd876f1cd10815257411 100644 (file)
@@ -1604,6 +1604,58 @@ int ti_sci_cmd_get_resource_range_from_shost(const struct ti_sci_handle *handle,
                                         range_start, range_num);
 }
 
+/**
+ * ti_sci_cmd_query_msmc() - Command to query currently available msmc memory
+ * @handle:            pointer to TI SCI handle
+ * @msms_start:                MSMC start as returned by tisci
+ * @msmc_end:          MSMC end as returned by tisci
+ *
+ * Return: 0 if all went well, else returns appropriate error value.
+ */
+static int ti_sci_cmd_query_msmc(const struct ti_sci_handle *handle,
+                                u64 *msmc_start, u64 *msmc_end)
+{
+       struct ti_sci_msg_resp_query_msmc *resp;
+       struct ti_sci_msg_hdr req;
+       struct ti_sci_info *info;
+       struct ti_sci_xfer *xfer;
+       int ret = 0;
+
+       if (IS_ERR(handle))
+               return PTR_ERR(handle);
+       if (!handle)
+               return -EINVAL;
+
+       info = handle_to_ti_sci_info(handle);
+
+       xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_QUERY_MSMC,
+                                    TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
+                                    (u32 *)&req, sizeof(req), sizeof(*resp));
+       if (IS_ERR(xfer)) {
+               ret = PTR_ERR(xfer);
+               dev_err(info->dev, "Message alloc failed(%d)\n", ret);
+               return ret;
+       }
+
+       ret = ti_sci_do_xfer(info, xfer);
+       if (ret) {
+               dev_err(dev, "Mbox send fail %d\n", ret);
+               return ret;
+       }
+
+       resp = (struct ti_sci_msg_resp_query_msmc *)xfer->tx_message.buf;
+
+       if (!ti_sci_is_response_ack(resp))
+               return -ENODEV;
+
+       *msmc_start = ((u64)resp->msmc_start_high << TISCI_ADDR_HIGH_SHIFT) |
+                       resp->msmc_start_low;
+       *msmc_end = ((u64)resp->msmc_end_high << TISCI_ADDR_HIGH_SHIFT) |
+                       resp->msmc_end_low;
+
+       return ret;
+}
+
 /**
  * ti_sci_cmd_proc_request() - Command to request a physical processor control
  * @handle:    Pointer to TI SCI handle
@@ -2426,6 +2478,7 @@ static void ti_sci_setup_ops(struct ti_sci_info *info)
        cops->get_freq = ti_sci_cmd_clk_get_freq;
 
        core_ops->reboot_device = ti_sci_cmd_core_reboot;
+       core_ops->query_msmc = ti_sci_cmd_query_msmc;
 
        rm_core_ops->get_range = ti_sci_cmd_get_resource_range;
        rm_core_ops->get_range_from_shost =
index 0998460099263c981a42c773c9d7263700ae1931..2d87cdd2cf96a0d66c31bdb6cee9f9acf97c5cb2 100644 (file)
@@ -25,6 +25,7 @@
 #define TI_SCI_MSG_BOARD_CONFIG_RM     0x000c
 #define TI_SCI_MSG_BOARD_CONFIG_SECURITY  0x000d
 #define TI_SCI_MSG_BOARD_CONFIG_PM     0x000e
+#define TISCI_MSG_QUERY_MSMC           0x0020
 
 /* Device requests */
 #define TI_SCI_MSG_SET_DEVICE_STATE    0x0200
@@ -161,6 +162,24 @@ struct ti_sci_msg_board_config {
        u16 boardcfg_size;
 } __packed;
 
+/**
+ * struct ti_sci_msg_resp_query_msmc - Query msmc message response structure
+ * @hdr:               Generic Header
+ * @msmc_start_low:    Lower 32 bit of msmc start
+ * @msmc_start_high:   Upper 32 bit of msmc start
+ * @msmc_end_low:      Lower 32 bit of msmc end
+ * @msmc_end_high:     Upper 32 bit of msmc end
+ *
+ * Response to a generic message with message type TISCI_MSG_QUERY_MSMC
+ */
+struct ti_sci_msg_resp_query_msmc {
+       struct ti_sci_msg_hdr hdr;
+       u32 msmc_start_low;
+       u32 msmc_start_high;
+       u32 msmc_end_low;
+       u32 msmc_end_high;
+} __packed;
+
 /**
  * struct ti_sci_msg_req_set_device_state - Set the desired state of the device
  * @hdr:               Generic header
index 49baf98ce7d07c741063d8a2e94c2db8f7a2ba17..222cf665460ff294b5344764f700fcc82818ad5f 100644 (file)
@@ -242,9 +242,13 @@ struct ti_sci_rm_core_ops {
  * @reboot_device: Reboot the SoC
  *             Returns 0 for successful request(ideally should never return),
  *             else returns corresponding error value.
+ * @query_msmc: Query the size of available msmc
+ *             Return 0 for successful query else appropriate error value.
  */
 struct ti_sci_core_ops {
        int (*reboot_device)(const struct ti_sci_handle *handle);
+       int (*query_msmc)(const struct ti_sci_handle *handle,
+                         u64 *msmc_start, u64 *msmc_end);
 };
 
 /**