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
64 spinlock_t xfer_lock;64 spinlock_t xfer_lock;
65};65};
66 66
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 */
78struct ti_sci_rm_type_map {
79 u32 dev_id;
80 u16 type;
81};
82
67/**83/**
68 * struct ti_sci_desc - Description of SoC integration84 * struct ti_sci_desc - Description of SoC integration
69 * @default_host_id: Host identifier representing the compute entity85 * @default_host_id: Host identifier representing the compute entity
@@ -71,12 +87,14 @@ struct ti_sci_xfers_info { · 1 unmodified line
71 * @max_msgs: Maximum number of messages that can be pending87 * @max_msgs: Maximum number of messages that can be pending
72 * simultaneously in the system88 * simultaneously in the system
73 * @max_msg_size: Maximum size of data per message that can be handled.89 * @max_msg_size: Maximum size of data per message that can be handled.
90 * @rm_type_map: RM resource type mapping structure.
74 */91 */
75struct ti_sci_desc {92struct ti_sci_desc {
76 u8 default_host_id;93 u8 default_host_id;
77 int max_rx_timeout_ms;94 int max_rx_timeout_ms;
78 int max_msgs;95 int max_msgs;
79 int max_msg_size;96 int max_msg_size;
97 struct ti_sci_rm_type_map *rm_type_map;
80};98};
81 99
82/**100/**
@@ -1600,6 +1618,153 @@ fail: · 1517 unmodified lines
1600 return ret;1618 return ret;
1601}1619}
1602 1620
1621static 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 */
1662static 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
1719fail:
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 */
1737static 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 */
1759static
1760int 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
1603/*1768/*
1604 * ti_sci_setup_ops() - Setup the operations structures1769 * ti_sci_setup_ops() - Setup the operations structures
1605 * @info: pointer to TISCI pointer1770 * @info: pointer to TISCI pointer
@@ -1610,6 +1775,7 @@ static void ti_sci_setup_ops(struct ti_sci_info *info) · 4 unmodified lines
1610 struct ti_sci_core_ops *core_ops = &ops->core_ops;1775 struct ti_sci_core_ops *core_ops = &ops->core_ops;
1611 struct ti_sci_dev_ops *dops = &ops->dev_ops;1776 struct ti_sci_dev_ops *dops = &ops->dev_ops;
1612 struct ti_sci_clk_ops *cops = &ops->clk_ops;1777 struct ti_sci_clk_ops *cops = &ops->clk_ops;
1778 struct ti_sci_rm_core_ops *rm_core_ops = &ops->rm_core_ops;
1613 1779
1614 core_ops->reboot_device = ti_sci_cmd_core_reboot;1780 core_ops->reboot_device = ti_sci_cmd_core_reboot;
1615 1781
@@ -1640,6 +1806,10 @@ static void ti_sci_setup_ops(struct ti_sci_info *info) · 24 unmodified lines
1640 cops->get_best_match_freq = ti_sci_cmd_clk_get_match_freq;1806 cops->get_best_match_freq = ti_sci_cmd_clk_get_match_freq;
1641 cops->set_freq = ti_sci_cmd_clk_set_freq;1807 cops->set_freq = ti_sci_cmd_clk_set_freq;
1642 cops->get_freq = ti_sci_cmd_clk_get_freq;1808 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;
1643}1813}
1644 1814
1645/**1815/**
drivers/firmware/ti_sci.h+42−0
@@ -35,6 +35,9 @@ · 34 unmodified lines
35#define TI_SCI_MSG_QUERY_CLOCK_FREQ 0x010d35#define TI_SCI_MSG_QUERY_CLOCK_FREQ 0x010d
36#define TI_SCI_MSG_GET_CLOCK_FREQ 0x010e36#define TI_SCI_MSG_GET_CLOCK_FREQ 0x010e
37 37
38/* Resource Management Requests */
39#define TI_SCI_MSG_GET_RESOURCE_RANGE 0x1500
40
38/**41/**
39 * struct ti_sci_msg_hdr - Generic Message Header for All messages and responses42 * struct ti_sci_msg_hdr - Generic Message Header for All messages and responses
40 * @type: Type of messages: One of TI_SCI_MSG* values43 * @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
461 u64 freq_hz;464 u64 freq_hz;
462} __packed;465} __packed;
463 466
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 */
483struct 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 */
500struct 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
464#endif /* __TI_SCI_H */506#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
192 u64 *current_freq);192 u64 *current_freq);
193};193};
194 194
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 */
212struct 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
195/**220/**
196 * struct ti_sci_ops - Function support for TI SCI221 * struct ti_sci_ops - Function support for TI SCI
197 * @dev_ops: Device specific operations222 * @dev_ops: Device specific operations
198 * @clk_ops: Clock specific operations223 * @clk_ops: Clock specific operations
224 * @rm_core_ops: Resource management core operations.
199 */225 */
200struct ti_sci_ops {226struct ti_sci_ops {
201 struct ti_sci_core_ops core_ops;227 struct ti_sci_core_ops core_ops;
202 struct ti_sci_dev_ops dev_ops;228 struct ti_sci_dev_ops dev_ops;
203 struct ti_sci_clk_ops clk_ops;229 struct ti_sci_clk_ops clk_ops;
230 struct ti_sci_rm_core_ops rm_core_ops;
204};231};
205 232
206/**233/**

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