History

firmware: ti_sci: Add support for RM core ops

TISCI provides support for getting the resources(IRQ, RING etc..) assigned to a specific device. These resources can be handled by the client and in turn sends TISCI cmd to configure the resources. It is very important that client should keep track on usage of these resources. Add support for TISCI commands to get resource ranges.

Lokesh Vutla committed 7 years ago

Commit 9c19fb61 parent 905c3043 files · +239 −0Browse files

Unified · Split

3 files
  1. drivers/firmware/ti_sci.c +170 −0
  2. drivers/firmware/ti_sci.h +42 −0
  3. include/linux/soc/ti/ti_sci_protocol.h +27 −0
drivers/firmware/ti_sci.c+170−0
@@ -64,6 +64,22 @@ struct ti_sci_xfers_info { · 63 unmodified lines
6464 spinlock_t xfer_lock;
6565 };
6666
67+/**
68+ * struct ti_sci_rm_type_map - Structure representing TISCI Resource
69+ * management representation of dev_ids.
70+ * @dev_id: TISCI device ID
71+ * @type: Corresponding id as identified by TISCI RM.
72+ *
73+ * Note: This is used only as a work around for using RM range apis
74+ * for AM654 SoC. For future SoCs dev_id will be used as type
75+ * for RM range APIs. In order to maintain ABI backward compatibility
76+ * type is not being changed for AM654 SoC.
77+ */
78+struct ti_sci_rm_type_map {
79+ u32 dev_id;
80+ u16 type;
81+};
82+
6783 /**
6884 * struct ti_sci_desc - Description of SoC integration
6985 * @default_host_id: Host identifier representing the compute entity
@@ -71,12 +87,14 @@ struct ti_sci_xfers_info { · 1 unmodified line
7187 * @max_msgs: Maximum number of messages that can be pending
7288 * simultaneously in the system
7389 * @max_msg_size: Maximum size of data per message that can be handled.
90+ * @rm_type_map: RM resource type mapping structure.
7491 */
7592 struct ti_sci_desc {
7693 u8 default_host_id;
7794 int max_rx_timeout_ms;
7895 int max_msgs;
7996 int max_msg_size;
97+ struct ti_sci_rm_type_map *rm_type_map;
8098 };
8199
82100 /**
@@ -1600,6 +1618,153 @@ fail: · 1517 unmodified lines
16001618 return ret;
16011619 }
16021620
1621+static int ti_sci_get_resource_type(struct ti_sci_info *info, u16 dev_id,
1622+ u16 *type)
1623+{
1624+ struct ti_sci_rm_type_map *rm_type_map = info->desc->rm_type_map;
1625+ bool found = false;
1626+ int i;
1627+
1628+ /* If map is not provided then assume dev_id is used as type */
1629+ if (!rm_type_map) {
1630+ *type = dev_id;
1631+ return 0;
1632+ }
1633+
1634+ for (i = 0; rm_type_map[i].dev_id; i++) {
1635+ if (rm_type_map[i].dev_id == dev_id) {
1636+ *type = rm_type_map[i].type;
1637+ found = true;
1638+ break;
1639+ }
1640+ }
1641+
1642+ if (!found)
1643+ return -EINVAL;
1644+
1645+ return 0;
1646+}
1647+
1648+/**
1649+ * ti_sci_get_resource_range - Helper to get a range of resources assigned
1650+ * to a host. Resource is uniquely identified by
1651+ * type and subtype.
1652+ * @handle: Pointer to TISCI handle.
1653+ * @dev_id: TISCI device ID.
1654+ * @subtype: Resource assignment subtype that is being requested
1655+ * from the given device.
1656+ * @s_host: Host processor ID to which the resources are allocated
1657+ * @range_start: Start index of the resource range
1658+ * @range_num: Number of resources in the range
1659+ *
1660+ * Return: 0 if all went fine, else return appropriate error.
1661+ */
1662+static int ti_sci_get_resource_range(const struct ti_sci_handle *handle,
1663+ u32 dev_id, u8 subtype, u8 s_host,
1664+ u16 *range_start, u16 *range_num)
1665+{
1666+ struct ti_sci_msg_resp_get_resource_range *resp;
1667+ struct ti_sci_msg_req_get_resource_range *req;
1668+ struct ti_sci_xfer *xfer;
1669+ struct ti_sci_info *info;
1670+ struct device *dev;
1671+ u16 type;
1672+ int ret = 0;
1673+
1674+ if (IS_ERR(handle))
1675+ return PTR_ERR(handle);
1676+ if (!handle)
1677+ return -EINVAL;
1678+
1679+ info = handle_to_ti_sci_info(handle);
1680+ dev = info->dev;
1681+
1682+ xfer = ti_sci_get_one_xfer(info, TI_SCI_MSG_GET_RESOURCE_RANGE,
1683+ TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1684+ sizeof(*req), sizeof(*resp));
1685+ if (IS_ERR(xfer)) {
1686+ ret = PTR_ERR(xfer);
1687+ dev_err(dev, "Message alloc failed(%d)\n", ret);
1688+ return ret;
1689+ }
1690+
1691+ ret = ti_sci_get_resource_type(info, dev_id, &type);
1692+ if (ret) {
1693+ dev_err(dev, "rm type lookup failed for %u\n", dev_id);
1694+ goto fail;
1695+ }
1696+
1697+ req = (struct ti_sci_msg_req_get_resource_range *)xfer->xfer_buf;
1698+ req->secondary_host = s_host;
1699+ req->type = type & MSG_RM_RESOURCE_TYPE_MASK;
1700+ req->subtype = subtype & MSG_RM_RESOURCE_SUBTYPE_MASK;
1701+
1702+ ret = ti_sci_do_xfer(info, xfer);
1703+ if (ret) {
1704+ dev_err(dev, "Mbox send fail %d\n", ret);
1705+ goto fail;
1706+ }
1707+
1708+ resp = (struct ti_sci_msg_resp_get_resource_range *)xfer->xfer_buf;
1709+
1710+ if (!ti_sci_is_response_ack(resp)) {
1711+ ret = -ENODEV;
1712+ } else if (!resp->range_start && !resp->range_num) {
1713+ ret = -ENODEV;
1714+ } else {
1715+ *range_start = resp->range_start;
1716+ *range_num = resp->range_num;
1717+ };
1718+
1719+fail:
1720+ ti_sci_put_one_xfer(&info->minfo, xfer);
1721+
1722+ return ret;
1723+}
1724+
1725+/**
1726+ * ti_sci_cmd_get_resource_range - Get a range of resources assigned to host
1727+ * that is same as ti sci interface host.
1728+ * @handle: Pointer to TISCI handle.
1729+ * @dev_id: TISCI device ID.
1730+ * @subtype: Resource assignment subtype that is being requested
1731+ * from the given device.
1732+ * @range_start: Start index of the resource range
1733+ * @range_num: Number of resources in the range
1734+ *
1735+ * Return: 0 if all went fine, else return appropriate error.
1736+ */
1737+static int ti_sci_cmd_get_resource_range(const struct ti_sci_handle *handle,
1738+ u32 dev_id, u8 subtype,
1739+ u16 *range_start, u16 *range_num)
1740+{
1741+ return ti_sci_get_resource_range(handle, dev_id, subtype,
1742+ TI_SCI_IRQ_SECONDARY_HOST_INVALID,
1743+ range_start, range_num);
1744+}
1745+
1746+/**
1747+ * ti_sci_cmd_get_resource_range_from_shost - Get a range of resources
1748+ * assigned to a specified host.
1749+ * @handle: Pointer to TISCI handle.
1750+ * @dev_id: TISCI device ID.
1751+ * @subtype: Resource assignment subtype that is being requested
1752+ * from the given device.
1753+ * @s_host: Host processor ID to which the resources are allocated
1754+ * @range_start: Start index of the resource range
1755+ * @range_num: Number of resources in the range
1756+ *
1757+ * Return: 0 if all went fine, else return appropriate error.
1758+ */
1759+static
1760+int ti_sci_cmd_get_resource_range_from_shost(const struct ti_sci_handle *handle,
1761+ u32 dev_id, u8 subtype, u8 s_host,
1762+ u16 *range_start, u16 *range_num)
1763+{
1764+ return ti_sci_get_resource_range(handle, dev_id, subtype, s_host,
1765+ range_start, range_num);
1766+}
1767+
16031768 /*
16041769 * ti_sci_setup_ops() - Setup the operations structures
16051770 * @info: pointer to TISCI pointer
@@ -1610,6 +1775,7 @@ static void ti_sci_setup_ops(struct ti_sci_info *info) · 4 unmodified lines
16101775 struct ti_sci_core_ops *core_ops = &ops->core_ops;
16111776 struct ti_sci_dev_ops *dops = &ops->dev_ops;
16121777 struct ti_sci_clk_ops *cops = &ops->clk_ops;
1778+ struct ti_sci_rm_core_ops *rm_core_ops = &ops->rm_core_ops;
16131779
16141780 core_ops->reboot_device = ti_sci_cmd_core_reboot;
16151781
@@ -1640,6 +1806,10 @@ static void ti_sci_setup_ops(struct ti_sci_info *info) · 24 unmodified lines
16401806 cops->get_best_match_freq = ti_sci_cmd_clk_get_match_freq;
16411807 cops->set_freq = ti_sci_cmd_clk_set_freq;
16421808 cops->get_freq = ti_sci_cmd_clk_get_freq;
1809+
1810+ rm_core_ops->get_range = ti_sci_cmd_get_resource_range;
1811+ rm_core_ops->get_range_from_shost =
1812+ ti_sci_cmd_get_resource_range_from_shost;
16431813 }
16441814
16451815 /**
drivers/firmware/ti_sci.h+42−0
@@ -35,6 +35,9 @@ · 34 unmodified lines
3535 #define TI_SCI_MSG_QUERY_CLOCK_FREQ 0x010d
3636 #define TI_SCI_MSG_GET_CLOCK_FREQ 0x010e
3737
38+/* Resource Management Requests */
39+#define TI_SCI_MSG_GET_RESOURCE_RANGE 0x1500
40+
3841 /**
3942 * struct ti_sci_msg_hdr - Generic Message Header for All messages and responses
4043 * @type: Type of messages: One of TI_SCI_MSG* values
@@ -461,4 +464,43 @@ struct ti_sci_msg_resp_get_clock_freq { · 420 unmodified lines
461464 u64 freq_hz;
462465 } __packed;
463466
467+#define TI_SCI_IRQ_SECONDARY_HOST_INVALID 0xff
468+
469+/**
470+ * struct ti_sci_msg_req_get_resource_range - Request to get a host's assigned
471+ * range of resources.
472+ * @hdr: Generic Header
473+ * @type: Unique resource assignment type
474+ * @subtype: Resource assignment subtype within the resource type.
475+ * @secondary_host: Host processing entity to which the resources are
476+ * allocated. This is required only when the destination
477+ * host id id different from ti sci interface host id,
478+ * else TI_SCI_IRQ_SECONDARY_HOST_INVALID can be passed.
479+ *
480+ * Request type is TI_SCI_MSG_GET_RESOURCE_RANGE. Responded with requested
481+ * resource range which is of type TI_SCI_MSG_GET_RESOURCE_RANGE.
482+ */
483+struct ti_sci_msg_req_get_resource_range {
484+ struct ti_sci_msg_hdr hdr;
485+#define MSG_RM_RESOURCE_TYPE_MASK GENMASK(9, 0)
486+#define MSG_RM_RESOURCE_SUBTYPE_MASK GENMASK(5, 0)
487+ u16 type;
488+ u8 subtype;
489+ u8 secondary_host;
490+} __packed;
491+
492+/**
493+ * struct ti_sci_msg_resp_get_resource_range - Response to resource get range.
494+ * @hdr: Generic Header
495+ * @range_start: Start index of the resource range.
496+ * @range_num: Number of resources in the range.
497+ *
498+ * Response to request TI_SCI_MSG_GET_RESOURCE_RANGE.
499+ */
500+struct ti_sci_msg_resp_get_resource_range {
501+ struct ti_sci_msg_hdr hdr;
502+ u16 range_start;
503+ u16 range_num;
504+} __packed;
505+
464506 #endif /* __TI_SCI_H */
include/linux/soc/ti/ti_sci_protocol.h+27−0
@@ -192,15 +192,42 @@ struct ti_sci_clk_ops { · 191 unmodified lines
192192 u64 *current_freq);
193193 };
194194
195+/**
196+ * struct ti_sci_rm_core_ops - Resource management core operations
197+ * @get_range: Get a range of resources belonging to ti sci host.
198+ * @get_rage_from_shost: Get a range of resources belonging to
199+ * specified host id.
200+ * - s_host: Host processing entity to which the
201+ * resources are allocated
202+ *
203+ * NOTE: for these functions, all the parameters are consolidated and defined
204+ * as below:
205+ * - handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
206+ * - dev_id: TISCI device ID.
207+ * - subtype: Resource assignment subtype that is being requested
208+ * from the given device.
209+ * - range_start: Start index of the resource range
210+ * - range_end: Number of resources in the range
211+ */
212+struct ti_sci_rm_core_ops {
213+ int (*get_range)(const struct ti_sci_handle *handle, u32 dev_id,
214+ u8 subtype, u16 *range_start, u16 *range_num);
215+ int (*get_range_from_shost)(const struct ti_sci_handle *handle,
216+ u32 dev_id, u8 subtype, u8 s_host,
217+ u16 *range_start, u16 *range_num);
218+};
219+
195220 /**
196221 * struct ti_sci_ops - Function support for TI SCI
197222 * @dev_ops: Device specific operations
198223 * @clk_ops: Clock specific operations
224+ * @rm_core_ops: Resource management core operations.
199225 */
200226 struct ti_sci_ops {
201227 struct ti_sci_core_ops core_ops;
202228 struct ti_sci_dev_ops dev_ops;
203229 struct ti_sci_clk_ops clk_ops;
230+ struct ti_sci_rm_core_ops rm_core_ops;
204231 };
205232
206233 /**

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t